forked from open-amdocs/webrix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
useDimensions.test.js
31 lines (28 loc) · 913 Bytes
/
useDimensions.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import React from 'react';
import {act} from 'react-dom/test-utils';
import {expect} from 'chai';
import {mount} from 'enzyme';
import useDimensions from './useDimensions';
const Elem = () => {
const {width, height} = useDimensions({current: {}});
return (
<div>{width},{height}</div>
);
};
describe('useDimensions()', () => {
it('Should return the previous value', async () => {
let wrapper = null;
let observed = 0, disconnected = 0;
window.ResizeObserver = class {
disconnect = () => disconnected++;
observe = () => observed++;
};
act(() => {wrapper = mount(<Elem/>)});
expect(wrapper.text()).to.eql('0,0');
expect(observed).to.eql(1);
expect(disconnected).to.eql(0);
act(() => {wrapper.unmount()});
expect(observed).to.eql(1);
expect(disconnected).to.eql(1);
});
});