test: add basic unit tests for all navigators

This commit is contained in:
Satyajit Sahoo
2020-06-30 16:14:52 +02:00
parent 2477db47a0
commit 9ba2f84d18
15 changed files with 279 additions and 43 deletions

View File

@@ -0,0 +1,33 @@
import * as React from 'react';
import { View, Text, Button } from 'react-native';
import { render, fireEvent } from 'react-native-testing-library';
import { NavigationContainer, ParamListBase } from '@react-navigation/native';
import { createStackNavigator, StackScreenProps } from '../index';
it('renders a stack navigator with screens', async () => {
const Test = ({ route, navigation }: StackScreenProps<ParamListBase>) => (
<View>
<Text>Screen {route.name}</Text>
<Button onPress={() => navigation.navigate('A')} title="Go to A" />
<Button onPress={() => navigation.navigate('B')} title="Go to B" />
</View>
);
const Stack = createStackNavigator();
const { findByText, queryByText } = render(
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="A" component={Test} />
<Stack.Screen name="B" component={Test} />
</Stack.Navigator>
</NavigationContainer>
);
expect(queryByText('Screen A')).not.toBeNull();
expect(queryByText('Screen B')).toBeNull();
fireEvent.press(await findByText('Go to B'));
expect(queryByText('Screen B')).not.toBeNull();
});