Skip to content

Commit

Permalink
test: add case for 'enable' parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyib committed Aug 22, 2023
1 parent de1df4d commit 6b4388d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/hooks/src/useEventListener/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,24 @@ describe('useEventListener', () => {
document.body.click();
expect(state).toBe(1);
});

it('test "enable" parameter', async () => {
let state: number = 0;
let enable = true;
const onClick = () => state++;
const { rerender, unmount } = renderHook(() =>
useEventListener('click', onClick, { target: () => container, enable }),
);

document.body.click();
expect(state).toBe(0);
container.click();
expect(state).toBe(1);

enable = false;
rerender();
container.click();
expect(state).toBe(1);
unmount();
});
});

0 comments on commit 6b4388d

Please sign in to comment.