Skip to content

Commit 9d4b3b7

Browse files
committed
Add adapter check and conditional to update or not
1 parent eeaebe3 commit 9d4b3b7

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
Memo,
2929
} from 'react-is';
3030
import { EnzymeAdapter } from 'enzyme';
31-
import { typeOfNode } from 'enzyme/build/Utils';
31+
import { typeOfNode, shallowEqual } from 'enzyme/build/Utils';
3232
import {
3333
displayNameOfNode,
3434
elementToTree as utilElementToTree,
@@ -617,10 +617,12 @@ class ReactSixteenAdapter extends EnzymeAdapter {
617617
return isElement(element);
618618
}
619619

620-
shouldUpdateComponent(root, nodes) {
621-
// not sure how to compare prevState/prevProps with current state/props for nodes here.
622-
// store values on the instance?
623-
return hasRootNodeChanged(root);
620+
shouldUpdateComponent(prevProps, root) {
621+
if (root.instance() !== null) {
622+
return (
623+
root.instance().updater._renderer._newState !== null || !shallowEqual(prevProps, root.instance().props)
624+
);
625+
}
624626
}
625627

626628
isValidElementType(object) {

packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ describe('shallow', () => {
11471147
expect(wrapper.find('.b').find('.c')).to.have.lengthOf(6);
11481148
});
11491149

1150-
it('is able to call find on the same wrapper more than once', () => {
1150+
it('can call find on the same wrapper more than once', () => {
11511151
class TestComponent extends React.Component {
11521152
render() {
11531153
return (
@@ -3609,10 +3609,6 @@ describe('shallow', () => {
36093609
});
36103610
});
36113611

3612-
describe('getNodesInternal', () => {
3613-
3614-
});
3615-
36163612
it('does not return true for HTML elements', () => {
36173613
const wrapper = shallow(<div className="bar baz" />);
36183614
expect(wrapper.isEmptyRender()).to.equal(false);

packages/enzyme/src/ShallowWrapper.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,14 @@ class ShallowWrapper {
361361
*/
362362
getNodesInternal() {
363363
const adapter = getAdapter(this[OPTIONS]);
364+
const prevProps = (this[UNRENDERED] && this[UNRENDERED].props) || {};
364365

365366
if (this[ROOT] === this && this.length === 1) {
366-
if (adapter.shouldUpdateComponent(this[ROOT], this[NODES])) {
367+
if (adapter.shouldUpdateComponent) {
368+
if (adapter.shouldUpdateComponent(prevProps, this[ROOT])) {
369+
this.update();
370+
}
371+
} else {
367372
this.update();
368373
}
369374
}

0 commit comments

Comments
 (0)