Skip to content

Latest commit

 

History

History
42 lines (32 loc) · 751 Bytes

unmount.md

File metadata and controls

42 lines (32 loc) · 751 Bytes

.unmount() => Self

A method that unmounts the component. This can be used to simulate a component going through an unmount/mount lifecycle.

Returns

ShallowWrapper: Returns itself.

Example

import PropTypes from 'prop-types';
import sinon from 'sinon';

const spy = sinon.spy();

class Foo extends React.Component {
  constructor(props) {
    super(props);
    this.componentWillUnmount = spy;
  }

  render() {
    const { id } = this.props;
    return (
      <div className={id}>
        {id}
      </div>
    );
  }
}
Foo.propTypes = {
  id: PropTypes.string.isRequired,
};
const wrapper = shallow(<Foo id="foo" />);
expect(spy.calledOnce).to.equal(false);
wrapper.unmount();
expect(spy.calledOnce).to.equal(true);