-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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 not behaving as a spy function after updating to 27.0.0 #11551
Comments
Thats intended You should spy on |
It's also worth pointing out that a spy should be set up after it('calls setInterval', () => {
jest.useFakeTimers()
setIntervalSpy = jest.spyOn(global, 'setInterval')
foobar()
// Works as intended
expect(setIntervalSpy).toHaveBeenCalled()
}) vs it('calls setInterval', () => {
setIntervalSpy = jest.spyOn(global, 'setInterval')
jest.useFakeTimers()
foobar()
// Expected number of calls: >= 1
// Received number of calls: 0
expect(setIntervalSpy).toHaveBeenCalled()
}) |
I don’t see where the changelog mentions this change? I came here from the Jest timers documentation that still has the old (now broken) code, just FYI. |
Even with your code @edmundask i don't get all call like i should.
and the test
it's always call 1 time only |
|
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
I updated my repository to use jest@27.0.0 and started to get error because of jest.setTimeout not behaving as a spy function anymore.
To Reproduce
created a simple project to demonstrate the issue
app.ts
app.test.js
Expected behavior
earlier the test should have passed perfectly without any issue but now I get the error
envinfo
envinfo
Edit:
just checked out release notes to see that with new jest release, it gives option to use
jest.useFakeTimers('modern')
andjest.useFakeTimers('legacy')
even tho legacy works fine now but I face the same error mentioned above while using'modern'
The text was updated successfully, but these errors were encountered: