enzymejs / enzyme

JavaScript Testing utilities for React
https://enzymejs.github.io/enzyme/
MIT License
19.95k stars 2.01k forks source link

When using React.memo(React.forwardRef(Component)) displayName will be inaccurate #2481

Closed mejackreed closed 3 years ago

mejackreed commented 3 years ago

Current behavior

When shallow rendering a component that has an inner displayName set wrapped in memo and forwardRef the displayName will be inaccurate.

Discussion in material-ui https://github.com/mui-org/material-ui/issues/23831

Upstream behavior added in React: https://github.com/facebook/react/pull/18925

So given the following:

const Foo = () => <div />;
Foo.displayName = 'CustomWrapper';

const MemoForwardFoo = React.memo(React.forwardRef(Foo));
expect(adapter.displayNameOfNode(<MemoForwardFoo />)).to.equal('Memo(ForwardRef(CustomWrapper))');

Currently : Memo([object object])

Expected behavior

From the React work, I would expect this to be CustomWrapper, but within Enzyme, it seems more like Memo(ForwardRef(CustomWrapper)) is the expectation

Your environment

API

Version

library version
enzyme 3.11.0
react >= 16.6
react-dom >= 16.6
react-test-renderer 16.14.0
adapter (below)

Adapter