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 3, 2022
1 parent 5f2f0b1 commit 9dfd35f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 8 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,12 @@ 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 });
// "works on a memoized functional component" test desires `Memo()` instead of `Memo`
return `Memo(${name})`;
}
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 9dfd35f

Please sign in to comment.