Closed tals closed 8 years ago
wops, duplicate
@tals What was it a duplicate of? I haven't yet found another issue reporting the same problem. (nice detailed report, btw)
This guy lol https://github.com/facebook/jest/issues/880
ty! 😇
@tals Thanks. Looks like a very hard to kill bug. :-)
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.
When a Jest test imports a module that includes:
Jest will blow up with
The reason for this is how Jest's mocking is slightly inaccurate, and this interacts badly with Babel's module system.
A Babel ES6 module defines:
export * from './stuff'
is implemented as:In Node, this is fine, because
Object.keys(_stuff)
return["dog"]
However, the Jest module mocks are inaccurate -- when you're collecting the object props, you don't keep track if it's enumerable.
You first get the slots with
getSlots()
:But collecting the metadata with getMetadata() only considers the value, and ignores property descriptors. So for
__esModule
, we get:and then gets placed in the mock. At this point,
Object.keys(_stuff)
returns["__esModule", "dog"]
, which causes the redefine error.