Skip to content

Commit

Permalink
Support getSnapshotBeforeUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
koba04 committed Jul 2, 2018
1 parent 477c47e commit d5dc160
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions packages/enzyme/src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,27 +288,24 @@ class ShallowWrapper {
if (
shouldRender &&
!this[OPTIONS].disableLifecycleMethods &&
instance &&
typeof instance.componentDidUpdate === 'function'
instance
) {
// getSnapshotBeforeUpdate
let snapshot;
if (
!this[OPTIONS].disableLifecycleMethods &&
instance
adapter.options.supportGetSnapshotBeforeUpdate
&& typeof instance.getSnapshotBeforeUpdate === 'function'
) {
if (
adapter.options.supportGetSnapshotBeforeUpdate
&& typeof instance.getSnapshotBeforeUpdate === 'function'
) {
const snapshot = instance.getSnapshotBeforeUpdate(prevProps, state);
if (typeof instance.componentDidUpdate === 'function') {
instance.componentDidUpdate(prevProps, state, snapshot);
}
} else if (typeof instance.componentDidUpdate === 'function') {
if (adapter.options.supportPrevContextArgumentOfComponentDidUpdate) {
instance.componentDidUpdate(prevProps, state, prevContext);
} else {
instance.componentDidUpdate(prevProps, state);
}
snapshot = instance.getSnapshotBeforeUpdate(prevProps, state);
}
// componentDidUpdate
if (typeof instance.componentDidUpdate === 'function') {
if (adapter.options.supportGetSnapshotBeforeUpdate) {
instance.componentDidUpdate(prevProps, state, snapshot);
} else if (adapter.options.supportPrevContextArgumentOfComponentDidUpdate) {
instance.componentDidUpdate(prevProps, state, prevContext);
} else {
instance.componentDidUpdate(prevProps, state);
}
}
// If it doesn't need to rerender, update only its props.
Expand Down

0 comments on commit d5dc160

Please sign in to comment.