Closed andrey-skl closed 8 years ago
I have a PR open (#20) that fixes this for text components. Other components will be possible, but marginally harder.
Using enzyme you can access both Children and props, https://github.com/airbnb/enzyme/blob/master/docs/api/shallow.md
The best way i found at the moment to get the content from a rendered component is to access it's children
prop using instance.prop('children');
This library is intended to work with a shallow renderer. It should not matter what View
renders, it should only matter what higher order components rendering a <div>
here is meaningless.
This API should work fine with shallow. Are you using something different?
cc @RealOrangeOne
@lelandrichardson actually looks like you're right and it should be enough to be able to get props via enzyme (which I use)
With the library only meant to be run using enzymes shallow
render (or similar), no the content of what's rendered doesnt really matter. In future I think it might be worth rendering relevant information (especially for elements like listviews etc). But I think for now, just access the children
prop as shown above.
for non-native components like ListView
, it might make sense to render something other than null
. Keep in mind though, you should be testing what your component renders, and relying on understanding what ListView's render tree looks like inside of your tests may not be the best idea. Regardless, it's a much more reasonable thing to do in that case versus doing so for <Text>
or <View>
.
Closing issue for now. Definately something that'd be great for someone to look into! Especially for things that render off function props such as ListView
.
For a shallow wrapper, you can call a wrapper.instance().props.propName to get the value of respective prop.
We render null everywhere https://github.com/lelandrichardson/react-native-mock/blob/master/src/components/View.js#L281
Just
Should be enough in most cases. Otherwise there is no proper way to check props and childten.