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
The below code does not work, with the error. Cannot set property bar of [object Object] which has only a getter import * as foo from './foo'; foo.bar = jest.fn();
Edit: After further investigation I've isolated it to the use case - Importing and then re-exporting objects/modules within a single object causes these objects/modules to become immutable which means I cannot stub them. Is this a known issue/is there a known work around?
To Reproduce
My source code looks something like this: https://repl.it/repls/SunnyRuddyTheory, but instead of the require I do: import * as abc from './add. This test passes since its using the babel 6 transpiled version, but with babel 7, it does not work.
Environment:
It works when used with babel 6, but does not work with babel 7.
It looks like babel has made this import * syntax such that the variable cannot be overridden. I have tested overriding the module works with default imports, but does not work with { Foo } object destructured imports nor import * imports.
Expected behavior
This should work with babel 7? Documented approaches such as: const spy = jest.spyOn(video, 'play'); would no longer work if this isn't resolved.
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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
🐛 Bug Report
The below code does not work, with the error.
Cannot set property bar of [object Object] which has only a getter
import * as foo from './foo'; foo.bar = jest.fn();
Edit: After further investigation I've isolated it to the use case - Importing and then re-exporting objects/modules within a single object causes these objects/modules to become immutable which means I cannot stub them. Is this a known issue/is there a known work around?
To Reproduce
My source code looks something like this:
https://repl.it/repls/SunnyRuddyTheory
, but instead of the require I do:import * as abc from './add
. This test passes since its using the babel 6 transpiled version, but with babel 7, it does not work.Environment:
It works when used with babel 6, but does not work with babel 7.
It looks like babel has made this import * syntax such that the variable cannot be overridden. I have tested overriding the module works with default imports, but does not work with { Foo } object destructured imports nor import * imports.
Expected behavior
This should work with babel 7? Documented approaches such as:
const spy = jest.spyOn(video, 'play');
would no longer work if this isn't resolved.Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: