-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Shallow Render has everything wrapped in ForwardRef
#2190
Comments
enzyme won't work properly with react-native without a react-native adapter. Follow #1436 for that. |
I am using the Adapter!
|
What i mean is, those adapters are for react web. There isn’t an adapter for react native atm. |
Thanks for the quick response. I think what is misleading to me is the documentation then? https://airbnb.io/enzyme/docs/guides/react-native.html "As of v0.18, React Native uses React as a dependency rather than a forked version of the library, which means it is now possible to use enzyme's shallow with React Native components". But if the behavior I am seeing is actually what is happening to everyone else, isn't this statement not really true? I guess you technically can use it, but it won't actually produce output thats predictable or usable. Should I make a pull request to the documentation to say that |
I suspect that at some point RN started using forwardRef in all their primitives, and that doesn’t play well with shallow. If you shallow render your own component, it should certainly be usable - you should be using |
@ljharb thank you! You just dropped the nugget of gold that I needed. In my example above, |
It’s likely that to “fix” this, RN itself would have to explicitly set the display name on their now-forward-reffed components. |
We have similar problem when using
I use Snapshot before fix:
Snapshot after fix:
|
After upgrading react-native to the 0.63.2, finding an element by testing id does not work anymore, because TouchableOpacity component is wrapped by Now it is retuning two nodes when I run:
I had the same problem after upgrading react-native version, and I can't do |
The solution I have figured out is to add the name of component (TouchableOpacity) in the
|
Current behavior
This is with react native. When I use
shallow
rendering with enzyme, all components seem to be wrapped in aforwardRef
. For example, if I do this in a testwhere
TestView
isThe resulting output is
The problem with this is that you cannot do
wrapper.find("Text")
, and instead have to dowrapper.find('ForwardRef(Text')
which is a lot less clear and seems fragile.Expected behavior
I would expect the component to be just
Your environment
React Native 0.59.5
API
Version
Adapter
The text was updated successfully, but these errors were encountered: