Open
Description
I was experiencing some unintuitive behavior from unmount
. I took the example from the docs:
it('Calls componentWillUnmount after unmount', () => {
const willMount = sinon.spy();
const didMount = sinon.spy();
const willUnmount = sinon.spy();
class Foo extends React.Component {
constructor(props) {
super(props);
this.componentWillUnmount = willUnmount;
this.componentWillMount = willMount;
this.componentDidMount = didMount;
}
render() {
return (
<div className={this.props.id}>
{this.props.id}
</div>
);
}
}
const wrapper = mount(<Foo id="foo" />);
expect(willMount.callCount).toEqual(1);
expect(didMount.callCount).toEqual(1);
expect(willUnmount.callCount).toEqual(0);
wrapper.unmount();
expect(willMount.callCount).toEqual(1);
expect(didMount.callCount).toEqual(1);
expect(willUnmount.callCount).toEqual(1);
})
And got the following result:
● <SurveyEditor/> › Test
expect(received).toEqual(expected)
Expected value to equal:
1
Received:
0
at Object.<anonymous> (client/pages/__tests__/SurveyEditor.jsx:180:35)
Line 180 corresponds to: expect(willUnmount.callCount).toEqual(1);
It seems as though componentWillUnmount
is not actually getting called. Relevant dependencies include:
- "enzyme": "^2.7.0",
- "jest": "^18.1.0",
- "jest-cli": "^18.1.0",
- "sinon": "^1.17.7",
- "babel-jest": "^18.0.0",