Skip to content

Commit

Permalink
[test]: usePageLeave
Browse files Browse the repository at this point in the history
  • Loading branch information
str0yka committed Jun 3, 2024
1 parent 628f065 commit cf09a47
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/hooks/usePageLeave/usePageLeave.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { act, renderHook } from '@testing-library/react';
import { act, fireEvent, renderHook } from '@testing-library/react';

import { usePageLeave } from './usePageLeave';

it('Should callback after the mouse has moved off the page', () => {
const callback = vi.fn();
renderHook(() => usePageLeave(callback));

act(() => document.dispatchEvent(new Event('mouseleave')));
act(() => fireEvent.mouseLeave(document));

expect(callback).toBeCalledTimes(1);
});
Expand All @@ -15,7 +15,7 @@ it("Shouldn't callback after the mouse has moved to the page", () => {
const callback = vi.fn();
renderHook(() => usePageLeave(callback));

act(() => document.dispatchEvent(new Event('mouseenter')));
act(() => fireEvent.mouseEnter(document));

expect(callback).not.toBeCalled();
});
Expand All @@ -24,12 +24,12 @@ it('Should be called more than once when the mouse goes off the page repeatedly'
const callback = vi.fn();
renderHook(() => usePageLeave(callback));

act(() => document.dispatchEvent(new Event('mouseleave')));
act(() => fireEvent.mouseLeave(document));

expect(callback).toBeCalledTimes(1);

act(() => document.dispatchEvent(new Event('mouseenter')));
act(() => document.dispatchEvent(new Event('mouseleave')));
act(() => fireEvent.mouseEnter(document));
act(() => fireEvent.mouseLeave(document));

expect(callback).toBeCalledTimes(2);
});

0 comments on commit cf09a47

Please sign in to comment.