mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-02-13 17:47:32 +08:00
test: add basic unit tests for all navigators
This commit is contained in:
33
packages/stack/src/__tests__/index.test.tsx
Normal file
33
packages/stack/src/__tests__/index.test.tsx
Normal 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();
|
||||
});
|
||||
Reference in New Issue
Block a user