Can I test the native features of React Native apps?
Short answer: no.
React Native Testing Library does not provide an entire React Native runtime since that would require running on a physical device or iOS simulator/Android emulator to provision the underlying OS and platform APIs.
using React Test Renderer while providing queries
and event APIs (
fireEvent) that mimicking certain behaviors from the actual runtime.
You can learn more about our testing environment here.
This approach has specific benefits and shortfalls. On the positive side:
- it allows testing most of the logic of regular React Native apps
- it allows running tests on any OS supported by Jest or other test runners, e.g., on CI
- it uses much less resources than full runtime simulation
- you can use Jest fake timers
On the negative side:
- you cannot test native features
Should I use/migrate to
There is no need to migrate existing test code to use
screen-bases queries. You can still use
queries and other functions returned by
screen object captures the latest
For new code, you are encouraged to use
screen as there are some good reasons for that, which are described in this article by Kent C. Dodds.
Should I use/migrate to User Event interactions?
We encourage you to migrate existing tests to use the User Event interactions, which offer more realistic event handling than the basic Fire Event API. Hence, it will provide more confidence in the quality of your code.