-
Notifications
You must be signed in to change notification settings - Fork 263
/
AppNavigator.test.js
44 lines (34 loc) 路 1.33 KB
/
AppNavigator.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
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', () => {
const component = (
<NavigationContainer>
<AppNavigator />
</NavigationContainer>
);
const { getByText, getAllByText } = render(component);
const header = getByText('List of numbers from 1 to 20');
const items = getAllByText(/Item number/);
expect(header).toBeTruthy();
expect(items.length).toBe(10);
});
test('clicking on one item takes you to the details screen', async () => {
const component = (
<NavigationContainer>
<AppNavigator />
</NavigationContainer>
);
const { getByText } = render(component);
const toClick = getByText('Item number 5');
fireEvent(toClick, 'press');
const newHeader = getByText('Showing details for 5');
const newBody = getByText('the number you have chosen is 5');
expect(newHeader).toBeTruthy();
expect(newBody).toBeTruthy();
});
});