Skip to content

Commit

Permalink
[core] Added unit test to cover use case
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacouille committed Oct 3, 2023
1 parent 53c0e0d commit 201c34e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@
version "0.0.0"
uid ""

"@mantine/[email protected].1":
version "7.1.1"
resolved "https://registry.yarnpkg.com/@mantine/store/-/store-7.1.1.tgz#859071535c97fc54862ffe946f58d95cb0455777"
integrity sha512-gCF59GbcRdAOqhrjWQczCAL3Hg+gMaiuATkXFCgbjkwIYXy22zlFAnSKckKHxWuRu7d51dJkPrGelnc7HtZQzA==
"@mantine/[email protected].2":
version "7.1.2"
resolved "https://registry.yarnpkg.com/@mantine/store/-/store-7.1.2.tgz#bbdf9b7e9f1f97978100868c1a705e4bc0ac7e74"
integrity sha512-Lf3FLymM0q92BuRC4tZxTxrb9EjVa+J8fqEV147u/Q3aUSNmkhJCqN2MXPbTHIBJ2PsbLtDhy/2edNyIK1KhKQ==

"@mantine/store@link:../src/mantine-store":
version "0.0.0"
Expand Down
14 changes: 14 additions & 0 deletions src/mantine-hooks/src/use-timeout/use-timeout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ describe('@mantine/hooks/use-timeout', () => {
expect(setTimeout).toHaveBeenCalled();
});

it('callback should be called when rerender is triggered before timeout', () => {
const { timeout, advanceTimerToNextTick } = setupTimer();
const { rerender, result } = renderHook(() => useTimeout(callback, timeout));

result.current.start();

rerender();

advanceTimerToNextTick();

expect(callback).toHaveBeenCalled();
expect(setTimeout).toHaveBeenCalled();
});

it('timeout is cleared on calling clear', () => {
const { timeout, advanceTimerToNextTick } = setupTimer(10);
const hook = renderHook(() => useTimeout(callback, timeout, { autoInvoke: false }));
Expand Down

0 comments on commit 201c34e

Please sign in to comment.