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
I found this issue when unit testing a server-side-only like component. To make it simple, below code snippet demo the problem.
class DummyComponent extends React.Component {
constructor() {
super(...arguments);
this.state = {
ready: false
};
}
componentDidMount() {
this.setState({ready: true});
}
render() {
// first render returns <div/>;
// re-render after mount will return <span/>
return this.state.ready ? <span/> : <div/>;
}
}
const wrapper = mount(<DummyComponent />);
The mount method report error like this.
Invariant Violation: dangerouslyReplaceNodeWithMarkup(...): Cannot render markup in a worker thread. Make sure `window` and `document` are available globally before requiring React when unit testing or use ReactDOMServer.renderToString() for server rendering.
Though the error message reads lacking of window and document. It is not the root cause. I have jsdom-global set up.
If the render function changes to return same type on re-render. The unit testing works fine.
It should be valid for one component to return different type of root element in re-render. I tried in in live app and it works. So, there must be something different in mount.
The text was updated successfully, but these errors were encountered:
I found this issue when unit testing a server-side-only like component. To make it simple, below code snippet demo the problem.
The
mount
method report error like this.Though the error message reads lacking of
window
anddocument
. It is not the root cause. I havejsdom-global
set up.If the
render
function changes to return same type on re-render. The unit testing works fine.It should be valid for one component to return different type of root element in re-render. I tried in in live app and it works. So, there must be something different in
mount
.The text was updated successfully, but these errors were encountered: