Skip to content

Commit bc269da

Browse files
committed
add test
1 parent 58eeea9 commit bc269da

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

test/usePopperSpec.js

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ import React from 'react';
33
import usePopper from '../src/usePopper';
44

55
describe('usePopper', () => {
6-
function renderHook(fn) {
6+
function renderHook(fn, initialProps) {
77
let result = { current: null };
88

9-
function Wrapper() {
10-
result.current = fn();
9+
function Wrapper(props) {
10+
result.current = fn(props);
1111
return null;
1212
}
1313

14-
result.mount = mount(<Wrapper />);
14+
result.mount = mount(<Wrapper {...initialProps} />);
15+
result.update = (props) => result.mount.setProps(props);
1516

1617
return result;
1718
}
@@ -51,13 +52,47 @@ describe('usePopper', () => {
5152
elements.popper.setAttribute('role', 'tooltip');
5253
elements.popper.setAttribute('id', 'example123');
5354

54-
renderHook(() => usePopper(elements.reference, elements.popper));
55+
const result = renderHook(() =>
56+
usePopper(elements.reference, elements.popper),
57+
);
5558

5659
setTimeout(() => {
5760
expect(
5861
document.querySelector('[aria-describedby="example123"]'),
5962
).to.equal(elements.reference);
6063

64+
result.mount.unmount();
65+
66+
expect(
67+
document.querySelector('[aria-describedby="example123"]'),
68+
).to.equal(null);
69+
70+
done();
71+
});
72+
});
73+
74+
it('should add to existing describedBy', (done) => {
75+
elements.popper.setAttribute('role', 'tooltip');
76+
elements.popper.setAttribute('id', 'example123');
77+
elements.reference.setAttribute('aria-describedby', 'foo, bar , baz ');
78+
79+
const result = renderHook(() =>
80+
usePopper(elements.reference, elements.popper),
81+
);
82+
83+
setTimeout(() => {
84+
expect(
85+
document.querySelector(
86+
'[aria-describedby="foo, bar , baz ,example123"]',
87+
),
88+
).to.equal(elements.reference);
89+
90+
result.mount.unmount();
91+
92+
expect(
93+
document.querySelector('[aria-describedby="foo, bar , baz "]'),
94+
).to.equal(elements.reference);
95+
6196
done();
6297
});
6398
});

0 commit comments

Comments
 (0)