Skip to content

Commit 7c6df01

Browse files
authored
docs: update React Navigation tests to use find queries (#364)
* docs: update React Navigation tests to use find queries * update test to be in sync with documentation
1 parent 9245d9e commit 7c6df01

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

examples/reactnavigation/src/__tests__/AppNavigator.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ import AppNavigator from '../AppNavigator';
88
jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
99

1010
describe('Testing react navigation', () => {
11-
test('page contains the header and 10 items', () => {
11+
test('page contains the header and 10 items', async () => {
1212
const component = (
1313
<NavigationContainer>
1414
<AppNavigator />
1515
</NavigationContainer>
1616
);
1717

18-
const { getByText, getAllByText } = render(component);
18+
const { findByText, findAllByText } = render(component);
1919

20-
const header = getByText('List of numbers from 1 to 20');
21-
const items = getAllByText(/Item number/);
20+
const header = await findByText('List of numbers from 1 to 20');
21+
const items = await findAllByText(/Item number/);
2222

2323
expect(header).toBeTruthy();
2424
expect(items.length).toBe(10);
@@ -31,12 +31,12 @@ describe('Testing react navigation', () => {
3131
</NavigationContainer>
3232
);
3333

34-
const { getByText } = render(component);
35-
const toClick = getByText('Item number 5');
34+
const { findByText } = render(component);
35+
const toClick = await findByText('Item number 5');
3636

3737
fireEvent(toClick, 'press');
38-
const newHeader = getByText('Showing details for 5');
39-
const newBody = getByText('the number you have chosen is 5');
38+
const newHeader = await findByText('Showing details for 5');
39+
const newBody = await findByText('the number you have chosen is 5');
4040

4141
expect(newHeader).toBeTruthy();
4242
expect(newBody).toBeTruthy();

website/docs/ReactNavigation.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,25 +154,25 @@ Let's a [`AppNavigator.test.js`](https://github.com/callstack/react-native-testi
154154
```jsx
155155
import React from 'react';
156156
import { NavigationContainer } from '@react-navigation/native';
157-
import { render, fireEvent, cleanup } from 'react-native-testing-library';
157+
import { render, fireEvent } from 'react-native-testing-library';
158158

159159
import AppNavigator from '../AppNavigator';
160160

161161
// Silence the warning https://github.com/facebook/react-native/issues/11094#issuecomment-263240420
162162
jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
163163

164164
describe('Testing react navigation', () => {
165-
test('page contains the header and 10 items', () => {
165+
test('page contains the header and 10 items', async () => {
166166
const component = (
167167
<NavigationContainer>
168168
<AppNavigator />
169169
</NavigationContainer>
170170
);
171171

172-
const { getByText, getAllByText } = render(component);
172+
const { findByText, findAllByText } = render(component);
173173

174-
const header = getByText('List of numbers from 1 to 20');
175-
const items = getAllByText(/Item number/);
174+
const header = await findByText('List of numbers from 1 to 20');
175+
const items = await findAllByText(/Item number/);
176176

177177
expect(header).toBeTruthy();
178178
expect(items.length).toBe(10);
@@ -185,12 +185,12 @@ describe('Testing react navigation', () => {
185185
</NavigationContainer>
186186
);
187187

188-
const { getByText } = render(component);
189-
const toClick = getByText('Item number 5');
188+
const { findByText } = render(component);
189+
const toClick = await findByText('Item number 5');
190190

191191
fireEvent(toClick, 'press');
192-
const newHeader = getByText('Showing details for 5');
193-
const newBody = getByText('the number you have chosen is 5');
192+
const newHeader = await findByText('Showing details for 5');
193+
const newBody = await findByText('the number you have chosen is 5');
194194

195195
expect(newHeader).toBeTruthy();
196196
expect(newBody).toBeTruthy();

0 commit comments

Comments
 (0)