React Native Testing Library
React Native Testing Library (RNTL) is a library inspired by React Testing Library.
It is not developed by, or affiliated with React Testing Library 😖.
Historically, there were two libraries:
However, the former has been deprecated in favor of the latter. This document concerns react-native-testing-library
. Clarified!
render()
render()
takes in similar arguments and options to the RTL equivalent:
tsx
const TestProviders = ({ children }) => {
return (
<StateProvider>
<ThemeProvider>
{children}
</ThemeProvider>
</StateProvider>
);
}
it('can render', () => {
render(<SomeAppComponent />, {
wrapper: TestProviders,
});
expect(screen.getByText("Hi!")).toBeDefined();
// Or maybe with jest-dom
expect(screen.getByText("Hi!")).toBeVisible();
})