diff --git a/packages/enzyme/src/ShallowWrapper.js b/packages/enzyme/src/ShallowWrapper.js index 1821370a3..bedb4f39c 100644 --- a/packages/enzyme/src/ShallowWrapper.js +++ b/packages/enzyme/src/ShallowWrapper.js @@ -339,22 +339,20 @@ class ShallowWrapper { instance ) { const lifecycles = getAdapterLifecycles(adapter); - // getSnapshotBeforeUpdate - let snapshot; - if ( - lifecycles.getSnapshotBeforeUpdate - && typeof instance.getSnapshotBeforeUpdate === 'function' - ) { - snapshot = instance.getSnapshotBeforeUpdate(prevProps, state); - } - // componentDidUpdate - if ( + + if (lifecycles.getSnapshotBeforeUpdate) { + let snapshot; + if (typeof instance.getSnapshotBeforeUpdate === 'function') { + snapshot = instance.getSnapshotBeforeUpdate(prevProps, state); + } + if (typeof instance.componentDidUpdate === 'function') { + instance.componentDidUpdate(prevProps, state, snapshot); + } + } else if ( lifecycles.componentDidUpdate && typeof instance.componentDidUpdate === 'function' ) { - if (lifecycles.getSnapshotBeforeUpdate) { - instance.componentDidUpdate(prevProps, state, snapshot); - } else if (lifecycles.componentDidUpdate.prevContext) { + if (lifecycles.componentDidUpdate.prevContext) { instance.componentDidUpdate(prevProps, state, prevContext); } else { instance.componentDidUpdate(prevProps, state);