enzyme: displayName set on forwardRef is not honored
Describe the bug In styled-components v4 beta we started decorating the forwardRef wrapper with displayName and various other statics to reduce the amount of interim component layers during rendering and preserve various library behaviors. https://github.com/styled-components/styled-components/blob/30c372cf635e0db77f74c0aaacf60deda729581c/src/models/StyledComponent.js#L249-L311
However, it doesn’t seem like enzyme surfaces a displayName
set on a forwardRef component.
To Reproduce See this codesandbox: https://codesandbox.io/s/yv7l2p76q9
Expected behavior The test expectations should work since name and displayName are set on the forwardRef node.
It would be really great if this could work for a few reasons:
-
Shallow rendering does not currently render the immediate child of ForwardRef, so if we modified our library so the wrapped child of ForwardRef had all the statics etc it still wouldn’t work without diving
-
The components don’t show up at all when using “find” off of “mount” since ForwardRef isn’t honoring displayName
Sidebar: I really wish ref forwarding was implemented as a decorator or class mixin… sigh.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 17 (7 by maintainers)
Commits related to this issue
- [enzyme-adapter-react-{16,16.3}] [fix] `forwardRef`: respect `.displayName` on the forwardRef Fixes #1810. — committed to enzymejs/enzyme by ljharb 6 years ago
- [enzyme-adapter-react-{16,16.3}] [fix] `forwardRef`: respect `.displayName` on the forwardRef Fixes #1810. — committed to enzymejs/enzyme by ljharb 6 years ago
Made a PR against React to support this: https://github.com/facebook/react/pull/13615
@jackson-sandland would you mind filing a new issue covering all this? I’ll be happy to take a look at it ASAP.
If DevTools doesn’t show it that sounds more like a bug with DevTools that we can fix.