RealOrangeOne / react-native-mock

A fully mocked and test-friendly version of react native (maintainers wanted)
MIT License
571 stars 153 forks source link

It'd better to render something instead of null #33

Closed andrey-skl closed 8 years ago

andrey-skl commented 8 years ago

We render null everywhere https://github.com/lelandrichardson/react-native-mock/blob/master/src/components/View.js#L281

Just

render() {
  return <div {...props}>{props.children}</div>;
}

Should be enough in most cases. Otherwise there is no proper way to check props and childten.

RealOrangeOne commented 8 years ago

I have a PR open (#20) that fixes this for text components. Other components will be possible, but marginally harder.

iyawnis commented 8 years ago

Using enzyme you can access both Children and props, https://github.com/airbnb/enzyme/blob/master/docs/api/shallow.md

RealOrangeOne commented 8 years ago

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');

lelandrichardson commented 8 years ago

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

andrey-skl commented 8 years ago

@lelandrichardson actually looks like you're right and it should be enough to be able to get props via enzyme (which I use)

RealOrangeOne commented 8 years ago

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.

lelandrichardson commented 8 years ago

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

RealOrangeOne commented 8 years ago

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.

ghost commented 6 years ago

For a shallow wrapper, you can call a wrapper.instance().props.propName to get the value of respective prop.