You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://github.com/callstack/react-native-testing-library/stargazers)
12
+
[![Version][version-badge]][package]
13
+
[![Build Status][build-badge]][build]
14
+
[![Code Coverage][coverage-badge]][coverage]
15
+
[![Downloads][downloads-badge]][downloads]
16
+
[![MIT License][license-badge]][license]
17
+
[![Sponsored by Callstack][callstack-badge]][callstack]
20
18
21
19
## The problem
22
20
23
21
You want to write maintainable tests for your React Native components. As a part of this goal, you want your tests to avoid including implementation details of your components and rather focus on making your tests give you the confidence for which they are intended. As part of this, you want your tests to be maintainable in the long run so refactors of your components (changes to implementation but not functionality) don't break your tests and slow you and your team down.
24
22
25
23
## This solution
26
24
27
-
The React Native Testing Library (RNTL) is a lightweight solution for testing React Native components. It provides light utility functions on top of `react-test-renderer`, in a way that encourages better testing practices. Its primary guiding principle is:
25
+
The React Native Testing Library (RNTL) is a comprehensive solution for testing React Native components. It provides React Native runtime simulation on top of `react-test-renderer`, in a way that encourages better testing practices. Its primary guiding principle is:
28
26
29
27
> The more your tests resemble the way your software is used, the more confidence they can give you.
30
28
@@ -34,19 +32,15 @@ This project is inspired by [React Testing Library](https://github.com/testing-l
This library has a `peerDependencies` listing for `react-test-renderer`. Make sure that your `react-test-renderer` version matches exactly the `react` version.
43
+
This library has a `peerDependencies` listing for `react-test-renderer`. Make sure that your `react-test-renderer` version matches exactly the `react` version, avoid using `^` in version number.
50
44
51
45
### Additional Jest matchers
52
46
@@ -56,32 +50,6 @@ You can use the built-in Jest matchers by adding the following line to your `jes
We generally advise using the "react-native" preset when testing with this library.
62
-
63
-
However, if you use React Native version earlier than 0.71 with [modern Jest fake timers](https://jestjs.io/blog/2020/05/05/jest-26#new-fake-timers) (default since Jest 27), you'll need to apply this custom Jest preset or otherwise awaiting promises, like using `waitFor` or `findBy*`, queries will fail with a timeout.
64
-
65
-
This is a [known issue](https://github.com/facebook/react-native/issues/29303). It happens because React Native's Jest preset overrides native Promise. Our preset restores it to defaults, which is not a problem in most apps out there.
66
-
67
-
Here's how you apply a custom preset in your Jest config:
68
-
69
-
```json
70
-
{
71
-
"preset": "@testing-library/react-native"
72
-
}
73
-
```
74
-
75
-
If this doesn't work for you, please fall back to using "legacy" fake timers.
76
-
77
-
### Flow
78
-
79
-
Note for [Flow](https://flow.org) users – you'll also need to install typings for `react-test-renderer`:
80
-
81
-
```sh
82
-
flow-typed install react-test-renderer
83
-
```
84
-
85
53
## Example
86
54
87
55
```jsx
@@ -162,11 +130,13 @@ Supported and used by [Rally Health](https://www.rallyhealth.com/careers).
0 commit comments