Difference between react-native-testing-library vs native-testing-library?

Viewed 327

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 ?

1 Answers

testing-library/native-testing-library is suggesting to use callstack/testing-library on github, however the npm package for @testing-library/react-native@7.x.x points to the repository https://github.com/callstack/react-native-testing-library.

In the docs:

You may have noticed a strange v2 to v7 upgrade, skipping versions 3, 4, 5 and 6. This is because we renamed the react-native-testing-library npm 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-native below 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.

Related