-
Notifications
You must be signed in to change notification settings - Fork 147
Unable to mock .mjs
files
#786
Comments
Hi @theKashey! Can you clarify things a bit more. It's not clear to me what is and isn't working based on your example repo and the scenario's you've posted. I don't know what "require |
rewiremock('./foo').withDefault(() => 'fake-foo'); // mock `foo`
index = (await import('./index')).default; // require `index` Then I am trying to run different scenarios manually renaming files.
|
Thank you! Ideally mocking shouldn't work for |
🤯 So - the old ways to mock are dying, but what about new ways? As long as (module-level) dependency mocking is an essential part of any testing - it shall be possible. We don't have any other variant (sinon stubbing is not a variant). |
The |
Yep. That's why I am asking for advice. Right now it makes There should be a way to mock |
When Node officially supports mocking then you can I guess. For |
Ok, so I have to open issue for a |
The problem is tracked elsewhere - nodejs/modules#98 |
Thanks @theKashey! But there's still a consistency issue on our end to track 😸 |
Let's define two files -
foo
andindex
. Then lets mock them usingModule._load
based mocker.Scenario 1 - all
.js
foo.js
to returnbar
foo.js
- 👍index.js
- 👍Scenario 2 -
foo.mjs
+index.js
foo.mjs
to returnbar
foo.mjs
- 👍index.js
- 👍Scenario 3 -
foo.mjs
+index.mjs
foo.mjs
to returnbar
foo.mjs
- 👍index.mjs
- 👎 <<---------, whilefoo.mjs
is still mocked.Scenario 3 -
foo.js
+index.mjs
Probably this is a feature, not a bug. But how then mock
.mjs
?Example: https://github.com/theKashey/rewiremock-esm-repro
The text was updated successfully, but these errors were encountered: