Skip to content

Commit

Permalink
Merge pull request #807 from koba04/fix-update-props-with-lifecycle-e…
Browse files Browse the repository at this point in the history
…xperimental

Fix a bug that doesn't update props with lifecycleExperimental: true and sCU: false
  • Loading branch information
aweary authored Feb 15, 2017
2 parents 0742607 + 2383dd8 commit eff8f1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ class ShallowWrapper {
instance.componentDidUpdate(prevProps, state, prevContext);
}
this.update();
// If it doesn't need to rerender, update only its props.
} else if (props) {
instance.props = props;
}
if (originalComponentWillReceiveProps) {
instance.componentWillReceiveProps = originalComponentWillReceiveProps;
Expand Down
7 changes: 7 additions & 0 deletions test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2862,8 +2862,11 @@ describe('shallow', () => {
}

const wrapper = shallow(<Foo foo="bar" />, { lifecycleExperimental: true });
expect(wrapper.instance().props.foo).to.equal('bar');
wrapper.setProps({ foo: 'baz' });
expect(wrapper.instance().props.foo).to.equal('baz');
wrapper.setProps({ foo: 'bax' });
expect(wrapper.instance().props.foo).to.equal('bax');
expect(spy.args).to.deep.equal([
['render'],
['componentWillReceiveProps'],
Expand Down Expand Up @@ -3050,7 +3053,9 @@ describe('shallow', () => {
}
}
const wrapper = shallow(<Foo />, { lifecycleExperimental: true });
expect(wrapper.instance().state.foo).to.equal('bar');
wrapper.setState({ foo: 'baz' });
expect(wrapper.instance().state.foo).to.equal('baz');
expect(spy.args).to.deep.equal([['render'], ['shouldComponentUpdate']]);
});

Expand Down Expand Up @@ -3152,7 +3157,9 @@ describe('shallow', () => {
lifecycleExperimental: true,
},
);
expect(wrapper.instance().context.foo).to.equal('bar');
wrapper.setContext({ foo: 'baz' });
expect(wrapper.instance().context.foo).to.equal('baz');
expect(spy.args).to.deep.equal([
[
'render',
Expand Down

0 comments on commit eff8f1c

Please sign in to comment.