Skip to content

Commit 3b3ab38

Browse files
committed
Add a failed test case
1 parent 617a8ef commit 3b3ab38

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4796,6 +4796,42 @@ describe('shallow', () => {
47964796
expect(wrapper.state('foo')).to.equal('onChange update');
47974797
expect(spy).to.have.property('callCount', 2);
47984798
});
4799+
4800+
it('should call `componentDidUpdate` when component’s `setState` is called through a bound method', () => {
4801+
const spy = sinon.spy();
4802+
class Foo extends React.Component {
4803+
constructor(props) {
4804+
super(props);
4805+
this.state = {
4806+
foo: 'init',
4807+
};
4808+
this.onChange = this.onChange.bind(this);
4809+
}
4810+
4811+
componentDidUpdate() {
4812+
spy();
4813+
}
4814+
4815+
onChange() {
4816+
// enzyme can't handle the update because `this` is a ReactComponent instance,
4817+
// not a ShallowWrapper instance.
4818+
this.setState({ foo: 'onChange update' });
4819+
}
4820+
4821+
render() {
4822+
return (
4823+
<div>
4824+
{this.state.foo}
4825+
<button onClick={this.onChange}>click</button>
4826+
</div>
4827+
);
4828+
}
4829+
}
4830+
const wrapper = shallow(<Foo />);
4831+
wrapper.find('button').prop('onClick')();
4832+
expect(wrapper.state('foo')).to.equal('onChange update');
4833+
expect(spy).to.have.property('callCount', 1);
4834+
});
47994835
});
48004836

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

0 commit comments

Comments
 (0)