-
Notifications
You must be signed in to change notification settings - Fork 279
-
Hi,
I really could use help setting up a test for my LoginScreen. My goal is to test the screen not just the login button (and many more screens once that works) . But setting up the wrapper turns out to be quite the challenge.
I managed to get the redux provider to work, I quieted an annoying redux persistor error, and now after adding the navigation my test fails to find the login button on my login screen.
FYI I also have a tab navigator and I plan to extract the wrapper for repeated use in a test-util file but I reckon that is not relevant for the problem at hand.
Here's my test
LoginScreen.test.ts
test('renders correctly', () => { const Stack = createStackNavigator<AuthRoutes>(); render( <NavigationContainer> <Provider store={store}> <Stack.Screen name="Login" component={LoginScreen} /> </Provider> </NavigationContainer> ); const loginButtton = screen.getByText('Login'); expect(loginButtton).toBeOnTheScreen(); });
My App.tsx returns the following elements
return (<SafeAreaProvider onLayout={onLayoutRootView}>
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<BottomSheetModalProvider>
<ToastProvider>
<StatusBar
barStyle="dark-content"
backgroundColor="transparent"
/>
<AuthGuard>
<RootNavigator />
</AuthGuard>
</ToastProvider>
</BottomSheetModalProvider>
</PersistGate>
</Provider>
</SafeAreaProvider>)
And my RootNavigator return this
return (
<NavigationContainer>
<Stack.Navigator
screenOptions={{ headerShown: false, freezeOnBlur: true }}
>
{!isAuthenticated ? (
<Stack.Screen name="Auth" component={AuthNavigator} />
) : (
<Stack.Screen name="Main" component={MainNavigator} />
)}
</Stack.Navigator>
</NavigationContainer>
);
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
Hello @szkieb! The test looks fine, I can't tell what could be wrong here without a reproducible demo. If you do a screen.debug
after rendering what is output?
Beta Was this translation helpful? Give feedback.