-
Notifications
You must be signed in to change notification settings - Fork 273
Issue where react native fails to render with crash and render has no error #556
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
Comments
I think it would be great if this error could be emulated in RNTL, would it involve modifying react-test-renderer or could it be done in RNTL? You can do it in user-space right now by inspecting the function Component({ count }) {
return (
<View testID="someTestId">
{count && <Text>{count}</Text>}
</View>
);
}
it('should not render a 0 when passed count=0', () => {
const { getByTestId } = render(
<Component count={0} />
);
// Use getByTestId to make sure we're asserting on the correct children
expect(getByTestId('someTestId').children).not.toContain('0');
}); Again, this is fragile because if the offending child is ever wrapped in another element, causing it not to be a direct child of "someTestId" then the test will pass when it should fail. |
Hey! I'm happy I found this thread, I just ran into this issue myself. So, we used a conditional check before rendering, and the result was an empty string that ended up in a plain As aforementioned speaker @tom-sherman mentions, this can be validated by looking through the |
Closing in favour of feature request #1032 |
Describe the bug
When rendering code conditionally in react-native you can run into a "Text strings must be rendered within a component." error.
Example, which will cause react native app to crash/fail:
When rendering such a component with
render
it will succeed.Expected behaviour
Expected some form of a crash during rendering too. Instead, the component seems to be rendered successfully.
Steps to Reproduce
I created a reproduction using expo: https://github.com/hannojg/react-native-testing-library-issue
Interestingly it seems that the component can be rendered on the web. However, when you test with expo on iOS/android you will see that the App component can't be rendered.
When you run
yarn test
you will see that the test using this library succeeds.Versions
npmPackages:
@testing-library/react-native: ^7.0.2 => 7.0.2
react: 16.13.1 => 16.13.1
react-native: https://github.com/expo/react-native/archive/sdk-39.0.2.tar.gz => 0.63.2
Note: This happens also with bare react native.
The text was updated successfully, but these errors were encountered: