Skip to content

Commit

Permalink
Add a failed case that cDU is not called
Browse files Browse the repository at this point in the history
  • Loading branch information
koba04 committed Jul 4, 2018
1 parent eb55307 commit 193f40a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3976,6 +3976,35 @@ describe('shallow', () => {
});
});

context('component instance', () => {
it('should be called componentDidUpdate when the component.setState is called', () => {
const spy = sinon.spy();
class Foo extends React.Component {
constructor(props) {
super(props);
this.state = {
foo: 'init',
};
}
componentDidUpdate() {
spy();
}
onChange() {
// enzyme can't handle the update because `this` is a ReactComponent instance,
// not a ShallowWrapper instance.
this.setState({ foo: 'update' });
}
render() {
return <div>{this.state.foo}</div>;
}
}
const wrapper = shallow(<Foo />);
wrapper.instance().onChange();
expect(wrapper.state('foo')).to.equal('update');
expect(spy.calledOnce).to.equal(true); // This test is failed
});
});

describeIf(REACT16, 'support getSnapshotBeforeUpdate', () => {
it('should call getSnapshotBeforeUpdate and pass snapshot to componentDidUpdate', () => {
const spy = sinon.spy();
Expand Down

0 comments on commit 193f40a

Please sign in to comment.