-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReactWrapper.unmount() throws Cannot render markup in a worker thread. #395
Comments
Can you share the code for the test that is throwing this error? Thanks! |
I tried to find the root cause of this and I think I found it. Anyway, problem solved when modifying in simple commonjs require. |
Thanks for the update @tleunen! |
@tleunen Can you elaborate on this? I don't understand what was the fix. Anyway, having the same issue basically, calling it('doesnt work', () => {
const dispatchSpy = spy();
const globalDispatchSpy = spy(mockStore, 'dispatch');
const WrappedView = dfView(syncMockFetch, MOCK_SCHEMA, MockView);
const cmp = mount(
<WrappedView
model={{}}
store={mockStore}
dispatch={dispatchSpy}
/>
);
cmp.unmount();
}); Of course neither |
I had |
that's weird
|
@tomkis1 can you share a small example reproducing your issue (including the content of the mounted component)? I'm in Paris for ReactEurope this week but I can look at this when I get back if no one else does. |
import React from 'react';
import jsdom from 'jsdom';
import { mount } from 'enzyme';
const doc = jsdom.jsdom('<!doctype html><html><body></body></html>');
global.document = doc;
global.window = doc.defaultView;
describe('foo', () => {
it('works', () => {
mount(<div>Foo Bar</div>);
});
it('doesnt work', () => {
const mounted = mount(<div>Foo Bar</div>);
mounted.unmount();
});
}); stacktrace:
|
Somebody found a solution for this problem? |
Yes, @matthewgertner found a workaround. Can you please elaborate? |
I am having the same problem you had @tomkis1 , when I try to unmount the component I receive the same error message about the |
Sorry about the delay in posting a solution, here goes:
import jsdom from 'jsdom';
const doc = jsdom.jsdom('');
global.document = doc;
global.window = doc.defaultView;
global.navigator = {
userAgent: 'node.js',
}
const React = require('react')
const mount = require('enzyme').mount
describe('foo', () => {
it('works', () => {
mount(<div>Foo Bar</div>);
});
it('doesnt work', () => {
const mounted = mount(<div>Foo Bar</div>);
mounted.unmount();
});
}); |
@nfcampos The |
it's something like this: import React from 'react'
console.log('hey')
import jsdom from 'jsdom'
console.log('boo')
as for |
That's my scenario, I put the jsdom config on |
Running into the same issue with TypeScript transpiled files, that make it hard to require/order the imports. Is there any other known workaround? Really surprised this only happens when unmounting, since everything else works fine. |
I figured out what my issue was: Here's my /**
* This is used to set up the environment that's needed for most
* of the unit tests for the project which includes polyfilling,
* chai setup, and initializing the DOM with jsdom
*/
import 'babel-polyfill'
import chai from 'chai'
import sinonChai from 'sinon-chai'
import {jsdom} from 'jsdom'
chai.use(sinonChai)
global.document = jsdom('<body></body>')
global.window = document.defaultView
global.navigator = window.navigator
global.expect = chai.expect
// this has to happen after the globals are set up because `chai-enzyme`
// will require `enzyme`, which requires `react`, which ultimately
// requires `fbjs/lib/ExecutionEnvironment` which (at require time) will
// attempt to determine the current environment (this is where it checks
// for whether the globals are present). Hence, the globals need to be
// initialized before requiring `chai-enzyme`.
chai.use(require('chai-enzyme')()) |
I don't think this issue should be closed. |
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? |
In addition to @kentcdodds fixes, I managed to fix this issue by changing the order of my
|
thanks @jackbrown . the last point was essential for it to work for me |
To possibly help future debuggers. The equivalent of the line below should also be placed after jsdom. |
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.Any idea what could be the problem?
The text was updated successfully, but these errors were encountered: