You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently you can't mock external or built-in modules which makes it difficult if you code imports a module that may run some side-effects and you have no control over it.
There may be some built in modules which you need to stub out but don't have access to during a test run.
What is the feature you are proposing to solve the problem?
Allowing us to use the built-in test runner to mock modules entirely.
There has already been some work in this by @cjihrig
I think the biggest things missing before I can open a PR are related to ESM loaders and are tracked in #49472 and #49473.
Both of those issues look to be resolved now, I don't know what the current blockers are for this
What alternatives have you considered?
No response
The text was updated successfully, but these errors were encountered:
It's already possible to mock things as the test linked below using the experimental Customization Hook API (https://nodejs.org/api/module.html#customization-hooks). Note that it should work only on Node.js 18.19+/20.6+.
Here are the files to set it up, and as you can see, it's only using public APIs:
What is the problem this feature will solve?
Currently you can't mock external or built-in modules which makes it difficult if you code imports a module that may run some side-effects and you have no control over it.
There may be some built in modules which you need to stub out but don't have access to during a test run.
What is the feature you are proposing to solve the problem?
Allowing us to use the built-in test runner to mock modules entirely.
There has already been some work in this by @cjihrig
I think the biggest things missing before I can open a PR are related to ESM loaders and are tracked in #49472 and #49473.
Both of those issues look to be resolved now, I don't know what the current blockers are for this
What alternatives have you considered?
No response
The text was updated successfully, but these errors were encountered: