enzymejs/enzyme

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

Open

#941 建立於 2017年5月13日

在 GitHub 查看
 (6 留言) (3 反應) (0 負責人)JavaScript (19,979 star) (2,016 fork)batch import
API: mountbughelp wantedquestion

描述

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

貢獻者指南