From 2e2b3dd709e19b80a718a94dee5fa371084cb781 Mon Sep 17 00:00:00 2001 From: Drew Miller <49833875+wwdrew@users.noreply.github.com> Date: Sat, 30 May 2020 19:12:10 +0100 Subject: [PATCH 1/2] docs: update React Navigation tests to use find queries --- website/docs/ReactNavigation.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/website/docs/ReactNavigation.md b/website/docs/ReactNavigation.md index bdf574184..ea946611d 100644 --- a/website/docs/ReactNavigation.md +++ b/website/docs/ReactNavigation.md @@ -154,7 +154,7 @@ Let's a [`AppNavigator.test.js`](https://github.com/callstack/react-native-testi ```jsx import React from 'react'; import { NavigationContainer } from '@react-navigation/native'; -import { render, fireEvent, cleanup } from 'react-native-testing-library'; +import { render, fireEvent } from 'react-native-testing-library'; import AppNavigator from '../AppNavigator'; @@ -162,17 +162,17 @@ import AppNavigator from '../AppNavigator'; jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper'); describe('Testing react navigation', () => { - test('page contains the header and 10 items', () => { + test('page contains the header and 10 items', async () => { const component = ( ); - const { getByText, getAllByText } = render(component); + const { findByText, findAllByText } = render(component); - const header = getByText('List of numbers from 1 to 20'); - const items = getAllByText(/Item number/); + const header = await findByText('List of numbers from 1 to 20'); + const items = await findAllByText(/Item number/); expect(header).toBeTruthy(); expect(items.length).toBe(10); @@ -185,12 +185,12 @@ describe('Testing react navigation', () => { ); - const { getByText } = render(component); - const toClick = getByText('Item number 5'); + const { findByText } = render(component); + const toClick = await findByText('Item number 5'); fireEvent(toClick, 'press'); - const newHeader = getByText('Showing details for 5'); - const newBody = getByText('the number you have chosen is 5'); + const newHeader = await findByText('Showing details for 5'); + const newBody = await findByText('the number you have chosen is 5'); expect(newHeader).toBeTruthy(); expect(newBody).toBeTruthy(); From 31207fbfa3da2882d52741b0258cca6cdc53b745 Mon Sep 17 00:00:00 2001 From: Drew Miller <49833875+wwdrew@users.noreply.github.com> Date: Sun, 31 May 2020 10:48:22 +0100 Subject: [PATCH 2/2] update test to be in sync with documentation --- .../src/__tests__/AppNavigator.test.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/reactnavigation/src/__tests__/AppNavigator.test.js b/examples/reactnavigation/src/__tests__/AppNavigator.test.js index f9731215b..81ada1740 100644 --- a/examples/reactnavigation/src/__tests__/AppNavigator.test.js +++ b/examples/reactnavigation/src/__tests__/AppNavigator.test.js @@ -8,17 +8,17 @@ import AppNavigator from '../AppNavigator'; jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper'); describe('Testing react navigation', () => { - test('page contains the header and 10 items', () => { + test('page contains the header and 10 items', async () => { const component = ( ); - const { getByText, getAllByText } = render(component); + const { findByText, findAllByText } = render(component); - const header = getByText('List of numbers from 1 to 20'); - const items = getAllByText(/Item number/); + const header = await findByText('List of numbers from 1 to 20'); + const items = await findAllByText(/Item number/); expect(header).toBeTruthy(); expect(items.length).toBe(10); @@ -31,12 +31,12 @@ describe('Testing react navigation', () => { ); - const { getByText } = render(component); - const toClick = getByText('Item number 5'); + const { findByText } = render(component); + const toClick = await findByText('Item number 5'); fireEvent(toClick, 'press'); - const newHeader = getByText('Showing details for 5'); - const newBody = getByText('the number you have chosen is 5'); + const newHeader = await findByText('Showing details for 5'); + const newBody = await findByText('the number you have chosen is 5'); expect(newHeader).toBeTruthy(); expect(newBody).toBeTruthy();