enzymejs/enzyme

Unmount and then wrapper.mount() again does not work properly

Open

#941 opened on May 13, 2017

View on GitHub
 (6 comments) (3 reactions) (0 assignees)JavaScript (19,979 stars) (2,016 forks)batch import
API: mountbughelp wantedquestion

Description

Enzyme: 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

Contributor guide