Skip to content

Commit

Permalink
Fix displayNameOfNode for Memo components
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Aug 2, 2022
1 parent 8753a35 commit a7a7d75
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 7 additions & 4 deletions packages/enzyme-adapter-react-17/src/ReactSeventeenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ class ReactSeventeenAdapter extends EnzymeAdapter {
rootNode,
nodeHierarchy,
nodeTypeFromType,
adapter.displayNameOfNode,
adapter.displayNameOfNode.bind(adapter),
catchingType,
);
},
Expand Down Expand Up @@ -692,7 +692,7 @@ class ReactSeventeenAdapter extends EnzymeAdapter {
cachedNode,
nodeHierarchy.concat(cachedNode),
nodeTypeFromType,
adapter.displayNameOfNode,
adapter.displayNameOfNode.bind(adapter),
cachedNode.type,
);
},
Expand Down Expand Up @@ -818,8 +818,11 @@ class ReactSeventeenAdapter extends EnzymeAdapter {
case ContextConsumer || NaN: return 'ContextConsumer';
case ContextProvider || NaN: return 'ContextProvider';
case Memo || NaN: {
const nodeName = displayNameOfNode(node);
return typeof nodeName === 'string' ? nodeName : `Memo(${displayNameOfNode(type)})`;
if (type.displayName) {
return type.displayName;
}
const name = this.displayNameOfNode({ type: type.type });
return name ? `Memo(${name})` : 'Memo';
}
case ForwardRef || NaN: {
if (type.displayName) {
Expand Down
6 changes: 1 addition & 5 deletions packages/enzyme-test-suite/test/Utils-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,7 @@ describe('Utils', () => {
Foo.displayName = 'CustomWrapper';

const MemoForwardFoo = React.memo(React.forwardRef(Foo));
if (is('>= 17')) {
expect(adapter.displayNameOfNode(<MemoForwardFoo />)).to.equal('Memo([object Object])');
} else {
expect(adapter.displayNameOfNode(<MemoForwardFoo />)).to.equal('Memo(ForwardRef(CustomWrapper))');
}
expect(adapter.displayNameOfNode(<MemoForwardFoo />)).to.equal('Memo(ForwardRef(CustomWrapper))');
});
});
});
Expand Down

0 comments on commit a7a7d75

Please sign in to comment.