Skip to content

docs: update React Navigation tests to use find queries #364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions examples/reactnavigation/src/__tests__/AppNavigator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
<NavigationContainer>
<AppNavigator />
</NavigationContainer>
);

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);
Expand All @@ -31,12 +31,12 @@ describe('Testing react navigation', () => {
</NavigationContainer>
);

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();
Expand Down
18 changes: 9 additions & 9 deletions website/docs/ReactNavigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,25 +154,25 @@ 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';

// Silence the warning https://github.com/facebook/react-native/issues/11094#issuecomment-263240420
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 = (
<NavigationContainer>
<AppNavigator />
</NavigationContainer>
);

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);
Expand All @@ -185,12 +185,12 @@ describe('Testing react navigation', () => {
</NavigationContainer>
);

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();
Expand Down