react-native-testing-library icon indicating copy to clipboard operation
react-native-testing-library copied to clipboard

Feature: emulate "Text strings must be rendered within a component." error

Open mdjastrzebski opened this issue 3 years ago • 0 comments

Describe the Feature

React Native renderer throws error when string is rendered outside of Text component, e.g. directly under View or other native component. It seems that React Test Renderer that we use does not throw a similar error in this situation, which may lead to missed errors that RNTL could capture in tests.

This feature would emulate that behaviour by throwing error whenever string value is rendered outside of Text component.

Possible Implementations

As a first step we could analyse render tree after initial render and look for string children prop that are not children of Text component.

Then we would have to figure out a way to react to subsequent re-renders to trigger the validation again. Maybe a custom act wrapper that would invoke the validation.

Related Issues

This feature request is based on #556

mdjastrzebski avatar Aug 02 '22 21:08 mdjastrzebski