Skip to content

Commit

Permalink
added fix for 14
Browse files Browse the repository at this point in the history
  • Loading branch information
mul53 committed Dec 10, 2020
1 parent 48b8aa7 commit 76e0109
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/enzyme-adapter-react-14/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"license": "MIT",
"dependencies": {
"enzyme-adapter-utils": "^1.13.1",
"enzyme-shallow-equal": "^1.0.4",
"object.assign": "^4.1.0",
"object.values": "^1.1.1",
"prop-types": "^15.7.2",
Expand Down
47 changes: 47 additions & 0 deletions packages/enzyme-adapter-react-14/src/ReactFourteenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
wrapWithWrappingComponent,
getWrappingComponentMountRenderer,
} from 'enzyme-adapter-utils';
import { spyMethod } from 'enzyme/build/Utils';
import shallowEqual from 'enzyme-shallow-equal';

function typeToNodeType(type) {
if (typeof type === 'function') {
Expand Down Expand Up @@ -172,6 +174,51 @@ class ReactFourteenAdapter extends EnzymeAdapter {
isDOM = true;
} else {
isDOM = false;

const inst = renderer._instance;
if (inst) {
const { restore: restoreUpdateComponent } = spyMethod(
inst,
'updateComponent',
(originalUpadateComponentMethod) => function updateComponent(
transaction,
prevParentElement,
nextParentElement,
prevUnmaskedContext,
nextUnmaskedContext,
) {
if (prevParentElement === nextParentElement) {
const { restore: restoreProcessPendingState } = spyMethod(
inst,
'_processPendingState',
(originalProcessPendingStateMethod) => function _processPendingState(nextProps, nextContext) {
if (!shallowEqual(prevUnmaskedContext, nextUnmaskedContext)) {
if (inst._instance.componentWillReceiveProps) {
inst._instance.componentWillReceiveProps(nextProps, nextContext);
}
}

const result = originalProcessPendingStateMethod.call(inst, nextProps, nextContext);
restoreProcessPendingState();
return result;
},
);
}

const result = originalUpadateComponentMethod.call(
inst,
transaction,
prevParentElement,
nextParentElement,
prevUnmaskedContext,
nextUnmaskedContext,
);
restoreUpdateComponent();
return result;
},
);
}

return withSetStateAllowed(() => renderer.render(el, context));
}
},
Expand Down

0 comments on commit 76e0109

Please sign in to comment.