Skip to content

Commit

Permalink
Add a failed test case
Browse files Browse the repository at this point in the history
  • Loading branch information
koba04 committed Aug 9, 2018
1 parent 617a8ef commit 3b3ab38
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4796,6 +4796,42 @@ describe('shallow', () => {
expect(wrapper.state('foo')).to.equal('onChange update');
expect(spy).to.have.property('callCount', 2);
});

it('should call `componentDidUpdate` when component’s `setState` is called through a bound method', () => {
const spy = sinon.spy();
class Foo extends React.Component {
constructor(props) {
super(props);
this.state = {
foo: 'init',
};
this.onChange = this.onChange.bind(this);
}

componentDidUpdate() {
spy();
}

onChange() {
// enzyme can't handle the update because `this` is a ReactComponent instance,
// not a ShallowWrapper instance.
this.setState({ foo: 'onChange update' });
}

render() {
return (
<div>
{this.state.foo}
<button onClick={this.onChange}>click</button>
</div>
);
}
}
const wrapper = shallow(<Foo />);
wrapper.find('button').prop('onClick')();
expect(wrapper.state('foo')).to.equal('onChange update');
expect(spy).to.have.property('callCount', 1);
});
});

describeIf(is('>= 16'), 'support getSnapshotBeforeUpdate', () => {
Expand Down

0 comments on commit 3b3ab38

Please sign in to comment.