Skip to content

Issue where react native fails to render with crash and render has no error #556

@hannojg

Description

@hannojg

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:

  const text = 0;

  return (
    <View style={styles.container}>
      {text && <Text>{text}</Text>}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions