Skip to content

Commit 5861eae

Browse files
committed
clean up
1 parent abfc7b3 commit 5861eae

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

versioned_docs/version-7.x/testing.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Then we need to use this setup file in our jest config. You can add it under `se
4848

4949
Make sure that the path to the file in `setupFiles` is correct. Jest will run these files before running your tests, so it's the best place to put your global mocks.
5050

51-
If your configuration works correctly, you can skip this section, but in some unusual cases you will need to mock `react-native-screen` as well. To do so add the following code in `jest/setup.js` file:
51+
If your configuration works correctly, you can skip this section, but in some unusual cases you will need to mock `react-native-screens` as well. To do so add the following code in `jest/setup.js` file:
5252

5353
```js
5454
// Include this section form mocking react-native-screens
@@ -74,7 +74,7 @@ If you're not using Jest, then you'll need to mock these modules according to th
7474

7575
We recommend using [React Native Testing Library](https://callstack.github.io/react-native-testing-library/) along with [`jest-native`](https://github.com/testing-library/jest-native) to write your tests.
7676

77-
We are going to write example tests illustrating difference between navigate and push functions using Root Navigator defined below:
77+
We are going to write example tests illustrating the difference between navigate and push functions using Root Navigator defined below:
7878

7979
<Tabs groupId="example" queryString="example">
8080
<TabItem value="static" label="Static" default>
@@ -147,10 +147,13 @@ Navigate function test example:
147147
```js
148148
import { expect, test } from '@jest/globals';
149149
import { fireEvent, render, screen } from '@testing-library/react-native';
150-
import { NavigationContainer } from '@react-navigation/native';
150+
import {
151+
createNavigationContainerRef,
152+
NavigationContainer,
153+
} from '@react-navigation/native';
151154
import { RootNavigator } from './RootNavigator';
152155

153-
test('navigates to settings screen twice', async () => {
156+
test('navigates to settings screen twice', () => {
154157
const navigation = createNavigationContainerRef();
155158
render(
156159
<NavigationContainer ref={navigation}>
@@ -188,10 +191,13 @@ Push function test example:
188191
```js
189192
import { expect, test } from '@jest/globals';
190193
import { fireEvent, render, screen } from '@testing-library/react-native';
191-
import { NavigationContainer } from '@react-navigation/native';
194+
import {
195+
createNavigationContainerRef,
196+
NavigationContainer,
197+
} from '@react-navigation/native';
192198
import { RootNavigator } from './RootNavigator';
193199

194-
test('pushes settings screen twice', async () => {
200+
test('pushes settings screen twice', () => {
195201
const navigation = createNavigationContainerRef();
196202
render(
197203
<NavigationContainer ref={navigation}>
@@ -272,7 +278,7 @@ import { act, fireEvent, render, screen } from '@testing-library/react-native';
272278
import { NavigationContainer } from '@react-navigation/native';
273279
import { RootNavigator } from './RootNavigator';
274280

275-
test('navigates to settings screen after 10000 ms delay', async () => {
281+
test('navigates to settings screen after 10000 ms delay', () => {
276282
// Enable fake timers
277283
jest.useFakeTimers();
278284

@@ -287,7 +293,7 @@ test('navigates to settings screen after 10000 ms delay', async () => {
287293
expect(screen.queryByText('Profile')).toBeOnTheScreen();
288294
expect(screen.queryByText('Settings')).not.toBeOnTheScreen();
289295

290-
// jest.runAllTimers causes React state updates
296+
// jest.advanceTimersByTime causes React state updates
291297
// So it should be wrapped into act
292298
act(() => jest.advanceTimersByTime(10000));
293299

0 commit comments

Comments
 (0)