Skip to content

fix: do not use a real timeout in waitfor when using fake timers #1177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 31, 2022
Prev Previous commit
Next Next commit
tests: some improvements from review
  • Loading branch information
pierrezimmermann committed Oct 19, 2022
commit 6686095d0ee3bf510e7765b9c46e184641c82c97
4 changes: 2 additions & 2 deletions src/__tests__/waitFor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,15 @@ test.each([true, false])(

await expect(
async () =>
await waitFor(() => mockErrorFn(), {
await waitFor(mockErrorFn, {
timeout: WAIT_FOR_TIMEOUT,
interval: WAIT_FOR_INTERVAL,
})
).rejects.toThrow();

// Verify that even though time to perform check is longer than interval
// test won't timeout until number of checks * interval >= timeout
// ie fake timers have been advanced by timeout when waitfor rejects
// i.e. fake timers have been advanced (at least?) by timeout when waitFor rejects
expect(mockErrorFn).toHaveBeenCalledTimes(
WAIT_FOR_TIMEOUT / WAIT_FOR_INTERVAL + 1
);
Expand Down