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
<p>Lightweight React Native testing utilities helping you write better tests with less effort.</P>
9
+
<p>Simple and complete React Native testing utilities that encourage good testing practices.</P>
11
10
</div>
12
11
13
12
[![Version][version-badge]][package]
14
13
[![PRs Welcome][prs-welcome-badge]][prs-welcome]
15
14
[![Chat][chat-badge]][chat]
16
15
[![Sponsored by Callstack][callstack-badge]][callstack]
17
16
18
-
_Appreciation notice: This project is heavily inspired by [react-testing-library](https://github.com/testing-library/react-testing-library). Go check it out and use it to test your web React apps._
19
-
20
17
## The problem
21
18
22
-
You want to write maintainable tests for your React Native components without testing implementation details, but then you're told to use Enzyme, which you learn has no React Native adapter, meaning only shallow rendering is supported. And you want to render deep! But deep rendering may otherwise require jsdom (React Native isn't the web!), while doing deep rendering with `react-test-renderer` is so painful.
23
-
24
-
You would also like to use the newest React features, but you need to wait for your testing library's abstractions to catch up and it takes a while.
25
-
26
-
You finally want to approach testing using only best practices, while Enzyme may encourage assertions on implementation details.
19
+
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.
27
20
28
21
## This solution
29
22
30
-
The React Native Testing Library is a lightweight solution for testing your React Native components. It provides light utility functions on top of `react-test-renderer` letting you always be up to date with latest React features and write any component tests you like. But really not any, it prevents you from testing implementation details because we stand this is a very bad practice.
31
-
32
-
This library is a replacement for [Enzyme](http://airbnb.io/enzyme/). It is tested to work with Jest, but it should work with other test runners as well.
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:
49
24
50
-
fireEvent.changeText(answerInputs[0], 'a1');
51
-
fireEvent.changeText(answerInputs[1], 'a2');
52
-
fireEvent.press(getByText('Submit'));
25
+
> The more your tests resemble the way your software is used, the more confidence they can give you.
53
26
54
-
expect(mockFn).toBeCalledWith({
55
-
'1': { q:'q1', a:'a1' },
56
-
'2': { q:'q2', a:'a2' },
57
-
});
58
-
});
59
-
```
60
-
61
-
You can find the source of `QuestionsBoard` component and this example [here](https://github.com/callstack/react-native-testing-library/blob/master/src/__tests__/questionsBoard.test.js).
27
+
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.
This library has a peerDependencies listing for `react-test-renderer` and, of course, `react`. Make sure to install them too!
80
46
47
+
> 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.60 (which comes with React >=16.9.0).
48
+
81
49
### Additional Jest matchers
82
50
83
51
In order to use addtional React Native-specific jest matchers from [@testing-library/jest-native](https://github.com/testing-library/jest-native) package add it to your project:
@@ -111,7 +79,34 @@ Note for [Flow](https://flow.org) users – you'll also need to install typings
111
79
flow-typed install react-test-renderer
112
80
```
113
81
114
-
As you may have noticed, it's not tied to React Native at all – you can safely use it in your React components if you feel like not interacting directly with DOM.
You can find the source of `QuestionsBoard` component and this example [here](https://github.com/callstack/react-native-testing-library/blob/master/src/__tests__/questionsBoard.test.js).
Copy file name to clipboardExpand all lines: website/docs/GettingStarted.md
+41-35
Original file line number
Diff line number
Diff line change
@@ -5,44 +5,15 @@ title: Getting Started
5
5
6
6
## The problem
7
7
8
-
You want to write maintainable tests for your React Native components without testing implementation details, but then you're told to use Enzyme, which you learn has no React Native adapter, meaning only shallow rendering is supported. And you want to render deep! But deep rendering may otherwise require jsdom (React Native isn't the web!), while doing deep rendering with `react-test-renderer` is so painful.
9
-
10
-
You would also like to use the newest React features, but you need to wait for your testing library's abstractions to catch up and it takes a while.
11
-
12
-
You finally want to approach testing using only best practices, while Enzyme may encourage assertions on implementation details.
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.
13
9
14
10
## This solution
15
11
16
-
The React Native Testing Library is a lightweight solution for testing your React Native components. It provides light utility functions on top of `react-test-renderer` letting you always be up to date with latest React features and write any component tests you like. It also prevents you from testing implementation details because we believe this is a very bad practice.
17
-
18
-
This library is a replacement for [Enzyme](http://airbnb.io/enzyme/).
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:
35
13
36
-
fireEvent.changeText(answerInputs[0], 'a1');
37
-
fireEvent.changeText(answerInputs[1], 'a2');
38
-
fireEvent.press(getByText('Submit'));
14
+
> The more your tests resemble the way your software is used, the more confidence they can give you.
39
15
40
-
expect(mockFn).toBeCalledWith({
41
-
'1': { q:'q1', a:'a1' },
42
-
'2': { q:'q2', a:'a2' },
43
-
});
44
-
});
45
-
```
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.
46
17
47
18
You can find the source of `QuestionsBoard` component and this example [here](https://github.com/callstack/react-native-testing-library/blob/master/src/__tests__/questionsBoard.test.js).
This library has a peerDependencies listing for `react-test-renderer` and, of course, `react`. Make sure to install them too!
66
37
67
-
As you may have noticed, it's not tied to React Native at all – you can safely use it in your React components if you feel like not interacting directly with DOM.
68
-
69
38
:::info
70
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.60 (which comes with React >=16.9.0).
71
40
:::
@@ -94,3 +63,40 @@ Then automatically add it to your jest tests by using `setupFilesAfterEnv` optio
You can find the source of `QuestionsBoard` component and this example [here](https://github.com/callstack/react-native-testing-library/blob/master/src/__tests__/questionsBoard.test.js).
0 commit comments