Unmount and then wrapper.mount() again does not work properly
See original GitHub issueEnzyme: 2.8.2 React: 15.5.4
If we do wrapper.unmount(), and then wrapper.mount(), the component is not mounted properly. I can see an empty console output after mounting again.
Simple plain example as follows
class Foo extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div className={this.props.id}>
{this.props.id}
</div>
);
}
}
const wrapper = mount(<Foo id="foo" />);
console.log("log before unmounting", wrapper.mount().debug()); //This logs the component properly
wrapper.unmount();
console.log("Log again after mounting", wrapper.mount().debug());//this logs empty component
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Unmount and then wrapper.mount() again does not work ...
mount(), the component is not mounted properly. I can see an empty console output after mounting again. Simple plain example as follows class ......
Read more >React.Component
The render() function should be pure, meaning that it does not modify component ... Once a component instance is unmounted, it will never...
Read more >A Complete Guide to Testing React Hooks - Toptal
We will pick a sufficiently complex hook and work on testing it. ... We use beforeEach and afterEach to mount and unmount our...
Read more >React - How to Check if a Component is Mounted or Unmounted
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your...
Read more >API | React Native Testing Library - Open Source
Usually you should not need to call unmount as it is done automatically if your test runner supports afterEach hook (like Jest, mocha,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This may be fixed by #969
Hey guys,
According to the docs this should work. However the following test fails:
Are we doing something wrong?
Cheers!