-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
useFakeTimers no longer mocks out timer functions properly #11447
Comments
Worth noting that |
they are mocked, but they are not mock functions. This is on purpose. See #5171 (although that's not the PR that landed, it contains notes of all the differences between "modern" and "legacy" fake timers)
|
Would using They look a bit like this: beforeAll(() => {
jest.useFakeTimers();
});
afterAll(() => {
jest.useRealTimers();
});
test('<SomeComponent/>: just an example', async () => {
const { findByText, getByTestId, queryByText } = render(<SomeComponent />);
expect(queryByText('...')).not.toBeInTheDocument();
fireEvent.click(getByTestId('...'));
act(() => {
jest.advanceTimersByTime(5000);
});
expect(await findByText('...')).toBeInTheDocument();
}); |
Both timer systems are the same as in Jest 26, we've just flipped the default implementation |
Since this is closed, does that mean the docs have been updated to explain the need to call jest.spyOn(global, 'setTimeout')? Without that, I think youβre going to continue to get confused users and more duplicates of this bug. They docs for 27.0 effectively still document legacy mode. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
π Bug Report
With the new fakeTimers the setTimeout, setInterval, clearTimeout, clearInterval functions are no longer properly mocked
β waits 1 second before ending the game
To Reproduce
https://jestjs.io/docs/timer-mocks using the first example
Expected behavior
For timer functions to be mocked or docs to be updated to show how to get the same results
The text was updated successfully, but these errors were encountered: