Skip to content

Commit

Permalink
Call getDerivedStateFromProps even for setState of ShallowRenderer (#…
Browse files Browse the repository at this point in the history
…12676)
  • Loading branch information
koba04 authored and gaearon committed Apr 30, 2018
1 parent 4724f7d commit 59838c0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/ReactShallowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,8 @@ class ReactShallowRenderer {
this._instance.UNSAFE_componentWillReceiveProps(props, context);
}
}

this._updateStateFromStaticLifecycle(props);
}
this._updateStateFromStaticLifecycle(props);

// Read state after cWRP in case it calls setState
const state = this._newState || oldState;
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/ReactShallowRenderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('ReactShallowRenderer', () => {
const instance = shallowRenderer.getMountedInstance();
instance.setState({});

expect(logs).toEqual(['shouldComponentUpdate']);
expect(logs).toEqual(['getDerivedStateFromProps', 'shouldComponentUpdate']);

logs.splice(0);

Expand Down

0 comments on commit 59838c0

Please sign in to comment.