enzyme: ReactWrapper.unmount() throws Cannot render markup in a worker thread.
For some reasons, when I call unmount
on a react wrapper node, React throws an error saying I don’t have a DOM.
jsdom is initialized, before importing React and enzyme, but I still get this error on unmount.
I even checked if the dom was really initialized properly, with the same check React does, and it’s evaluated as true
so everything looks ok.
!!(
typeof window !== 'undefined' &&
window.document &&
window.document.createElement
)
Any idea what could be the problem?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 22 (3 by maintainers)
stacktrace:
I agree with @j-funk, something appears to be wrong here. If nothing else, this seems like it ought to be addressed within the documentation?
I figured out what my issue was:
Here’s my
setup-test-env.js
file now:Sorry about the delay in posting a solution, here goes:
react-dom
needsnavigator
to be a global (enzyme
importsreact-dom
)react
andenzyme
imports need to happen after the globals are attached (so they need to berequire
calls, becauseimport
s happen before anything else irrespective of where they appear in the fileI don’t think this issue should be closed.
To possibly help future debuggers.
The equivalent of the line below should also be placed after jsdom.
const Adapter = require('enzyme-adapter-react-15');
That’s my scenario, I put the jsdom config on
setup.js
and just import themount
andReact
on the test files. So I don’t know why still happens.In addition to @kentcdodds fixes, I managed to fix this issue by changing the order of my
test-setup.js
to the following: