I want to test my React Native code, but I am struggling about which testing library I should use.
According to what I've read on the internet, it is a better practice to focus on testing the user behavior than the internal logic of a component. That's why I use jest library with test-renderer.
There are two recommended libraries on the ReactNative official documentation that are equivalent to me: react-native-testing-library and @testing-library/react-native (also known as native-testing-library).
What's the difference between them ?
testing-library/native-testing-library is suggesting to use callstack/testing-library on github, however the npm package for @testing-library/[email protected] points to the repository https://github.com/callstack/react-native-testing-library.
In the docs:
You may have noticed a strange
v2tov7upgrade, skipping versions 3, 4, 5 and 6. This is because we renamed thereact-native-testing-librarynpm package to@testing-library/react-native, officially joining the "Testing Library" family 🎉. We're merging existing two libraries into a single one. The native-testing-library repository, which had v6, will soon be archived and using@testing-library/react-nativebelow v7, sourced from mentioned repository, is deprecated.For branding purposes we keep the "React Native Testing Library" name, similar to "React Testing Library". Only the npm published package is changing. The code repository also stays the same under Callstack governance.
In summary:
The codebase is essentially the same, (as it's from the same developers), however, since joining @testing-library, there was some administrative work to be done on the npm registry by the developers to consolidate the packages.
In the past there were to React Native Testing Libraries: @testing-library/react-native built by Brandon Carroll and react-native-testing-library by Callstack. Both of these libraries where modelled after React Testing Library by Kent C. Dodds, and relied on React Test Renderer for rendering components.
After some time, the later one has been more actively maintained and saw bigger adoption in the community. In Jun 2020 the former one (by Brandon Carroll) has been deprecated and the later one (by Callstack) has become the official React Native library in the Testing Library org, taking over the @testing-library/react-native NPM package name. During merge process the API of Callstack's library has been modified to allow for easier transition of users from the deprecated library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With