-
-
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
window.setImmediate has issues when used with jsdom environment. #11511
Comments
you are not using jsdom as environment in your repro Please read the documentation and blog post for jest 27 https://jestjs.io/blog |
The jest.config.js does not specify an environment, because I set those manually in the
As to demonstrate that 1/3 tests fail with the node environment and 3/3 test fails with the jsdom environment. |
Hm you are right, I checked my tests which I have around 3.3k and some of them rely on setImmediate to resolve the Promise queue for some tests
Jest bumped jsdom version so not sure if it is something from jsdom or jest mocks the setImmediate now |
It's not a global in the browsers, so we removed it from the JSDOM env: #11222 |
Hey, Then I'm not 100% sure of the reason, but we've seen problems using fake-indexeddb because of this change, when using fake timers. With the legacy fake timers, we get the error:
I believe this is from this line: where the legacy fake timers call With the modern fake timers, I get a timeout instead. I believe that in that case Fake-indexeddb uses the polyfill of setImmediate, and this results in using My guess is that this may bring problems in other codebases where polyfills for By chance, is there an easy way to opt-in to adding it in our environment? Or just have a way to reinstante the node implementation of Thanks! |
That's a bug in legacy timers, it should check for presence in |
I filed #11539. |
You'll need to polyfill it yourself or use a custom environment extending our JSDOM one |
Of course this doesn't work with
I see, I'll try something. Thanks for the answers! |
FYI I filed dumbmatter/fakeIndexedDB#64 in fakeIndexedDB repository. |
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
When using
window.setImmediate()
within jest (either as part of the test, or within the tested unit) using the jsdom testEnvironment, an unexpected exception is thrown:TypeError: setImmediate is not defined
Or, when using the legacy fakeTimers (
jest.useFakeTimers("legacy")
)TypeError: this._timerAPIs.setImmediate is not a function
To Reproduce
I made a reproduction repository here: https://github.com/StringEpsilon/jest_jsdom_setimmediate_bug
Clone it, npm install, npm test.
The setup runs 3 tests in both JSDOM and node environments. For the node environment, 1 out of 3 test fails as expected, for the missing DOM in mounting a component. The JSDOM environment run fails all 3 tests.
Expected behavior
window.setImmediate()
should work within the jsdom jest environment without throwing an exception.Link to repl or repo (highly encouraged)
https://github.com/StringEpsilon/jest_jsdom_setimmediate_bug
envinfo
The text was updated successfully, but these errors were encountered: