Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

Components with forwardRef fail when trying to get displayName #91

Closed
atomicpages opened this issue May 22, 2019 · 3 comments · Fixed by #92
Closed

Components with forwardRef fail when trying to get displayName #91

atomicpages opened this issue May 22, 2019 · 3 comments · Fixed by #92

Comments

@atomicpages
Copy link
Contributor

atomicpages commented May 22, 2019

Repro the issue using the following component:

import React from 'react';

const Button = React.forwardRef(({ children, ...rest }, ref) => <button {...rest} ref={ref}>{children}</button>);

export default Button;

The correct way to get the display name is not through JSX magic, but rather from the static member on the object. With function components jsx.type.prototype is undefined.

@bahmutov
Copy link
Contributor

bahmutov commented May 22, 2019 via email

@atomicpages
Copy link
Contributor Author

Already working on it :)

@atomicpages
Copy link
Contributor Author

atomicpages commented May 22, 2019

Turns out this is happening React.forwardRef is used. To handle this case I'm propose to use the same getDisplayName function used by react-devtools. This should make it more resilient

@atomicpages atomicpages changed the title Function components with React 16.8 fail Function components with forwardRef fail May 22, 2019
@atomicpages atomicpages changed the title Function components with forwardRef fail Components with forwardRef fail when trying to get displayName May 22, 2019
atomicpages pushed a commit to atomicpages/cypress-react-unit-test that referenced this issue May 22, 2019
* Adding tests for React.memo
* Adding tests for React.forwardRef
* Adding basic hook tests
bahmutov pushed a commit that referenced this issue Jun 5, 2019
* Fixing #91

* Adding tests for React.memo
* Adding tests for React.forwardRef
* Adding basic hook tests

* Fixing some issues

* Fixing bad .type property in get where the selector is a function
* Ensuring all specs pass
* Adding stub for hooks spec for the time being...
dmtrKovalenko pushed a commit to cypress-io/cypress that referenced this issue Oct 1, 2020
…-test#92)

* Fixing cypress-io/cypress-react-unit-test#91

* Adding tests for React.memo
* Adding tests for React.forwardRef
* Adding basic hook tests

* Fixing some issues

* Fixing bad .type property in get where the selector is a function
* Ensuring all specs pass
* Adding stub for hooks spec for the time being...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants