Skip to content

Commit

Permalink
Fix to call componentDidUpdate on setState of React v16
Browse files Browse the repository at this point in the history
  • Loading branch information
koba04 committed Oct 18, 2017
1 parent 9572a3e commit ce39a28
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 4 additions & 6 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3519,15 +3519,13 @@ describe('shallow', () => {
[
'render',
],
];
if (!REACT16) {
expected.push([
[
'componentDidUpdate',
{ foo: 'props' }, { foo: 'props' },
{ foo: 'bar' }, { foo: 'baz' },
{ foo: 'context' },
]);
}
REACT16 ? undefined : { foo: 'context' },
],
];
expect(spy.args).to.deep.equal(expected);
});

Expand Down
6 changes: 3 additions & 3 deletions packages/enzyme/src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class ShallowWrapper {

/**
* A method is for re-render with new props and context.
* This calls componentDidUpdate method if lifecycleExperimental is enabled.
* This calls componentDidUpdate method if disableLifecycleMethods is not enabled.
*
* NOTE: can only be called on a wrapper instance that is also the root instance.
*
Expand Down Expand Up @@ -387,7 +387,7 @@ class ShallowWrapper {
// so we replace shouldComponentUpdate to know the result and restore it later.
let originalShouldComponentUpdate;
if (
this[OPTIONS].lifecycleExperimental &&
!this[OPTIONS].disableLifecycleMethods &&
adapter.options.enableComponentDidUpdateOnSetState &&
instance &&
typeof instance.shouldComponentUpdate === 'function'
Expand All @@ -402,7 +402,7 @@ class ShallowWrapper {
instance.setState(state, callback);
if (
shouldRender &&
this[OPTIONS].lifecycleExperimental &&
!this[OPTIONS].disableLifecycleMethods &&
adapter.options.enableComponentDidUpdateOnSetState &&
instance &&
typeof instance.componentDidUpdate === 'function'
Expand Down

0 comments on commit ce39a28

Please sign in to comment.