-
-
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
[Bug]: Virtual mocks created with jest.unstable_mockModule
do not work outside of the test file
#15303
Comments
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Up My current way around this is to modify the Below are the changes I needed to make it work. As I said before, if you think these are okay I can post a PR with them. --- a/packages/jest-runtime/src/index.ts
+++ b/packages/jest-runtime/src/index.ts
@@ -1973,7 +1973,7 @@ class Runtime {
const options: ResolveModuleConfig = {conditions: this.esmConditions};
const moduleID = await this._resolver.getModuleIDAsync(
- this._virtualMocks,
+ this._virtualModuleMocks,
from,
moduleName,
options,
@@ -2019,7 +2019,7 @@ class Runtime {
// transitive unmocking for package managers that store flat packages (npm3)
const currentModuleID = await this._resolver.getModuleIDAsync(
- this._virtualMocks,
+ this._virtualModuleMocks,
from,
undefined,
options, Edit: Oops, I just realized my diff contained the changes I ported from #15080 as well! That's now fixed. |
Version
29.7.0, also tested on 30.0.0-alpha.6
Steps to reproduce
npm install
npm test
Expected behavior
Both tests should pass.
Actual behavior
Additional context
The error apparently comes from here (perhaps this could cause issues too, I am not sure) because the mock is checked against
this._virtualMocks
instead ofthis._virtualModuleMocks
. Checking against the correct map fixes my issue.I could open a PR with one or both changes if you think it is that simple. To me, it looked like this part of the code is used with ESM mocks only, but I did not get too deep in it and I may be wrong.
Environment
The text was updated successfully, but these errors were encountered: