-
-
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
Jest seems to share JSdom environments accross tests #7654
Comments
My guess is that Jest properly creates a new jsdom environment for each tests, but jsdom reuses its prototype objects. Which I think should be expected ? But if the configuration option |
That seems reasonable. Not sure if it's expected or not, you're supposed to be running inside of a sandbox. They might be open to a PR?
All |
@SimenB why is this happening in a |
Shouldn't really matter, but might be! Not sure what the correct semantics are here. @thymikee? |
My concern is that if it's in a |
Wondering if this could be the root cause for my other issue #7573 as well... 🤔 |
We're moving forward in our investigation on our project: even when restoring the mocks at the right moment, we still get intermittents because of the shared prototypes. Restoring mocks in |
@julienw I'm currently tackling a similar issue. Let me know if you find a solution! |
regarding Maybe we should do it in both in the current state of things. |
If I understand correctly, are you saying that even restoring mocks in |
JSDOM v16 has started migrating off of shred prototypes, btw: https://github.com/jsdom/jsdom/releases/tag/16.0.0. So we could close this issue and point to upstream |
yes.. it also highly depends on the order tests are run. For example working on some file would make the problem appear suddenly, because babel compiling the changed files changes the timing of running.
That's a great news! This would effectively fix the problem with jsdom! I still wonder why restoring mocks happen in |
Sure! It's on purpose, although I do agree it's not necessarily 100% expected https://github.com/facebook/jest/blob/faa52673f4d02ee1d273103ada9382a0805b54a4/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts#L56-L77 |
Thanks, I filed #9896. For anybody coming here, you can force the use of jsdom v16 by setting your test environment to |
Nah, let's close. We'll be including JSDOM@16 in Jest@26. People can track that in #9606 |
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
From the documentation in https://jestjs.io/docs/en/configuration#testenvironment-string, the test environment should be sandboxed:
But in our tests we're mocking some prototype methods and it looks like that they're shared, and this produces intermittents.
To Reproduce
Steps to reproduce the behavior:
This repository contains several times the same tests:
testcaseX.test.js
mocksHTMLElement.prototype.getBoundingClientRect
defaultX.test.js
doesn't mock this methodtestcaseX.test.js
have the same content, so they should have the same resultdefaultX.test.js
have the same content, so they should have the same resultAlso, the configuration contains:
But this doesn't seem to make a difference in the result. What does make a difference is these changes: https://github.com/julienw/testcase-jest1/compare/reset-mocks. So maybe the issue is the implementation for
resetMocks
and not the test environment?For me this fails nearly 100% of the time, but because this is likely a frequent intermittent you might need to repeat the test several times.
Here is the error I get:
Link to repl or repo (highly encouraged)
https://github.com/julienw/testcase-jest1
Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: