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
Copy file name to clipboardExpand all lines: website/docs/FAQ.md
+16-18
Original file line number
Diff line number
Diff line change
@@ -3,42 +3,40 @@ id: faq
3
3
title: FAQ
4
4
---
5
5
6
-
<details>
7
-
<summary>Can I test native features of React Native apps?</summary>
6
+
#### Can I test the native features of React Native apps?
8
7
9
-
<p>Short answer: no.</p>
8
+
Short answer: no.
10
9
11
-
React Native Testing Library does not provide a full React Native runtime since that would require running on physical device
10
+
React Native Testing Library does not provide an entire React Native runtime since that would require running on a physical device
12
11
or iOS simulator/Android emulator to provision the underlying OS and platform APIs.
13
12
14
-
Instead of using React Native renderer, it simulates only the JavaScript part of its runtime by
13
+
Instead of using React Native renderer, it simulates only the JavaScript part of its runtime
15
14
using [React Test Renderer](https://reactjs.org/docs/test-renderer.html) while providing queries
16
-
and `fireEvent` APIs that mimick certain behaviors from the real runtime.
15
+
and event APIs (`userEvent`, `fireEvent`) that mimicking certain behaviors from the actual runtime.
17
16
18
17
You can learn more about our testing environment [here](./TestingEnvironment.md).
19
18
20
-
This approach has certain benefits and shortfalls. On the positive side:
19
+
This approach has specific benefits and shortfalls. On the positive side:
21
20
22
21
- it allows testing most of the logic of regular React Native apps
23
-
- it allows running test on any OS supported by Jest, or other test runner, e.g. on CI
22
+
- it allows running tests on any OS supported by Jest or other test runners, e.g., on CI
24
23
- it uses much less resources than full runtime simulation
25
24
- you can use Jest fake timers
26
25
27
-
The the negative side:
26
+
On the negative side:
28
27
29
28
- you cannot test native features
30
-
-certain JavaScript features might not be perfectly simulated, but we are working on it
29
+
-it might not perfectly simulate certain JavaScript features, but we are working on it
31
30
32
-
For instance, [react-native's ScrollView](https://reactnative.dev/docs/scrollview) has several props that depend on native calls. While you can trigger `onScroll` call with `fireEvent.scroll`, `onMomentumScrollBegin` is called from the native side and will therefore not be called.
31
+
The [User Event interactions](user-event) solve some of the simulation issues, as they offer more realistic event handling than the basic [Fire Event API](api#fireevent-api).
33
32
34
-
</details>
35
-
36
-
<details>
37
-
<summary>Should I use/migrate to `screen` queries?</summary>
33
+
### Should I use/migrate to `screen` queries?
38
34
39
35
There is no need to migrate existing test code to use `screen`-bases queries. You can still use
40
-
queries and other functions returned by `render`. In fact `screen` hold just that value, the latest `render` result.
36
+
queries and other functions returned by `render`. The `screen` object captures the latest `render` result.
37
+
38
+
For new code, you are encouraged to use `screen` as there are some good reasons for that, which are described in [this article](https://kentcdodds.com/blog/common-mistakes-with-react-testing-library#not-using-screen) by Kent C. Dodds.
41
39
42
-
For newer code you can either use`screen` or `render` result destructuring. However, there are some good reasons to use `screen`, which are described in [this article](https://kentcdodds.com/blog/common-mistakes-with-react-testing-library#not-using-screen) by Kent C. Dodds.
40
+
### Should I use/migrate to User Event interactions?
43
41
44
-
</details>
42
+
We encourage you to migrate existing tests to use the [User Event interactions](user-event), which offer more realistic event handling than the basic [Fire Event API](api#fireevent-api). Hence, it will provide more confidence in the quality of your code.
Copy file name to clipboardExpand all lines: website/docs/GettingStarted.md
+9-9
Original file line number
Diff line number
Diff line change
@@ -5,17 +5,17 @@ title: Getting Started
5
5
6
6
## The problem
7
7
8
-
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 testbase 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.
8
+
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 focus on making your tests give you the confidence 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.
9
9
10
10
## This solution
11
11
12
-
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:
12
+
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:
13
13
14
-
> The more your tests resemble the way your software is used, the more confidence they can give you.
14
+
> The more your tests resemble how your software is used, the more confidence they can give you.
15
15
16
-
This project is inspired by [React Testing Library](https://github.com/testing-library/react-testing-library). Tested to work with Jest, but it should work with other test runners as well.
16
+
This project is inspired by [React Testing Library](https://github.com/testing-library/react-testing-library). It is tested to work with Jest, but it should work with other test runners as well.
17
17
18
-
You can find the source of `QuestionsBoard` component and this example [here](https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/questionsBoard.test.tsx).
18
+
You can find the source of the `QuestionsBoard` component and this example [here](https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/questionsBoard.test.tsx).
This library has a `peerDependencies` listing for `react-test-renderer`. Make sure that your `react-test-renderer` version matches exactly your `react` version.
36
+
This library has a peer dependency for `react-test-renderer` package. Make sure that your `react-test-renderer` version matches exactly your `react` version.
37
37
38
38
:::info
39
-
In order to properly use helpers for async tests (`findBy` queries and `waitFor`) you need at least React >=16.9.0 (featuring async `act`) or React Native >=0.61 (which comes with React >=16.9.0).
39
+
To properly use helpers for async tests (`findBy` queries and `waitFor`), you need at least React >=16.9.0 (featuring async `act`) or React Native >=0.61 (which comes with React >=16.9.0).
40
40
:::
41
41
42
42
### Additional Jest matchers
43
43
44
-
In order to use additional React Native-specific Jest matchers add the following line to your `jest-setup.ts` file (configured using [`setupFilesAfterEnv`](https://jestjs.io/docs/configuration#setupfilesafterenv-array)):
44
+
To use additional React Native-specific Jest matchers, add the following line to your `jest-setup.ts` file (configured using [`setupFilesAfterEnv`](https://jestjs.io/docs/configuration#setupfilesafterenv-array)):
You can find the source of `QuestionsBoard` component and this example [here](https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/questionsBoard.test.tsx).
83
+
You can find the source of the `QuestionsBoard` component and this example [here](https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/questionsBoard.test.tsx).
0 commit comments