-
-
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
Cannot expect(setTimeout) without legacy mode of useFakeTimers() #11521
Comments
seems like a duplicate of #11500 |
@Smrtnyk They might be related, but I'm describing a different symptom. I don't know if setTimeout is working or not. I don't get past expect(setTimeout) because the fake version of setTimeout does not appear to be a valid mock. |
@Smrtnyk I should have read through the other thread before responding. The discussion does seem to be going in the direction I thought this one might, so there is some duplication in that sense. It's the same underlying cause, but reported via a different use case. I see pros and cons to "duplicate" vs "related" but I don't care to split hair over it. :) I'm just glad that others are seeing the same thing. It's weird that it works in my repl.it though. |
Duplicate of #11447 |
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. |
💥 Regression Report
I upgraded to jest 27.0 and found my tests failed due to the change in
useFakeTimers()
.The error is:
It does work when I use the
"legacy"
option, however my usage is the recommended approach. I don't think it constitutes the "subtle implementation differences" described in your blog.Last working version
Worked up to version: 26.6.3
Stopped working in version: 27.0.4 (Probably 27.0.0)
To Reproduce
Steps to reproduce the behavior:
jest.useFakeTimers("modern");
(orjest.useFakeTimers()
in v27+)setTimeout
as a mock, such asexpect(setTimeout).toHaveBeenCalledTimes(0);
The problem might only happen on Windows, as I couldn't reproduce it in repl and everything else was the same.
Expected behavior
It should still work, as this is the technique described in your docs.
Link to repl or repo (highly encouraged)
repl.it demo
NOTE: The repl runs without error, but fails locally on my Windows 10 workstation. I confirmed I have an identical package-lock.json and have cleaned my npm cache etc. Might it be only an issue on Windows?
Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: