Created
August 11, 2020 22:13
-
-
Save ManuViola77/ebb7e47769a54b2fb6759eeefc912809 to your computer and use it in GitHub Desktop.
Navigation helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import {NavigationContainer} from '@react-navigation/native'; | |
import {createStackNavigator} from '@react-navigation/stack'; | |
import {render} from '@testing-library/react-native'; | |
const Stack = createStackNavigator(); | |
const renderOtherComponents = (otherComponents, screenConfig = {}) => { | |
return otherComponents.map(({name, component}) => { | |
return ( | |
<Stack.Screen | |
{...screenConfig} | |
key={name} | |
name={name} | |
component={component} | |
/> | |
); | |
}); | |
}; | |
export const renderWithNavigation = ( | |
mainComponent, | |
{otherComponents = [], navigatorConfig = {}, screenConfig = {}} = {}, | |
) => { | |
const App = () => ( | |
<NavigationContainer> | |
<Stack.Navigator {...navigatorConfig}> | |
<Stack.Screen | |
{...screenConfig} | |
name="TestNavigator" | |
component={mainComponent} | |
/> | |
{otherComponents && | |
renderOtherComponents(otherComponents, screenConfig)} | |
</Stack.Navigator> | |
</NavigationContainer> | |
); | |
return {...render(<App />)}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment