Skip to content

Commit

Permalink
refactor(test/staking): Change useDebounce test case. It was breaking…
Browse files Browse the repository at this point in the history
… in some runs.

Add a typing like situation and check the param passed down to the callback.
  • Loading branch information
brunomenezes committed Jan 28, 2025
1 parent 643171e commit 0c82d5b
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions apps/staking/__tests__/hooks/useDebounce.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,10 @@ describe('Hooks/useDebounce', () => {
const callback = jest.fn();
const delay = 400;
const { result } = renderHook(() => useDebounce(callback, delay));
['h', 'he', 'hell', 'hello'].forEach((arg) => result.current(arg));

const functionInvocations = Array.from({ length: 4 }).map(
() =>
new Promise<void>((resolve) => {
setTimeout(() => {
result.current();
resolve();
}, 100);
})
);
await Promise.all(functionInvocations);
await waitFor(() => expect(callback).toHaveBeenCalledTimes(1));

await waitFor(() => expect(callback).toHaveBeenCalledTimes(1), {
timeout: delay + 10,
});
expect(callback).toHaveBeenCalledWith('hello');
});
});

0 comments on commit 0c82d5b

Please sign in to comment.