-
-
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
It's impossible to reset modules when using ES6 import syntax #3236
Comments
Resetting the module registry doesn't do any good if you don't re-import or re-require the module afterward. See examples at https://facebook.github.io/jest/docs/jest-object.html#jestresetmodules. I think your options are to use |
Just as @jwbay said (thanks ❤️). Use |
Hi, I tried
And I add test file
The second test case was failed. But what I expected is all tests should be passed. And I tried
But jest said they run all tests in sandbox. How to understand sandbox here? |
Just in case someone else is also lost after trying above's solution but using
Requisites: configure the babel-plugin-dynamic-import-node babel plugin. Source: https://jestjs.io/docs/en/jest-object#jestdomockmodulename-factory-options |
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. |
If you are using ES6 import syntax, there is no way to reset modules between tests. The only workaround is to put tests in different files, or switch to non-standard require syntax.
For example, the following test suite will fail due to shared state:
Event using the resetModules option will not reset five because the reference has already been created.
There should be an option to run each test in complete isolation.
The text was updated successfully, but these errors were encountered: