Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The findByType method from react-test-renderer doesn't find ref-forwarding components #12723

Closed
p-jackson opened this issue May 1, 2018 · 2 comments

Comments

@p-jackson
Copy link
Contributor

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
In tests, if the component passed to root.findByType was created using forwardRef it can't be found.

If I use root.find to loop over all the nodes and log .type I see that the ref-forwarding-component is skipped entirely.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:

https://codesandbox.io/s/k0o70vjv07?module=%2Fsrc%2Findex.test.js

I expect the second test to work like the first, however the second test is failing.

What is the expected behavior?
This may just be the way that forwardRef works, but the reason I expected it to work is I'm using it to make wrapped controls, like the <FancyButton> example from the documentation. When writing tests I want to be able to find a FancyButton and test it's besing passed the correct props, and not have to check that the DOM rendered by FancyButton is correct; that's already being tested in fancy-button.test.js

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Using React 16.3.2, failing in Chrome and Node 8.11.0

I've tried all the 16.3.x versions in codesandbox and they all failed.

@p-jackson
Copy link
Contributor Author

Maybe related to #12693 ?

@gaearon
Copy link
Collaborator

gaearon commented May 1, 2018

Same as #12693, as far as I can see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants