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:

  1. 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

  2. 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

Most upvoted comments

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.