Skip to content

Instantly share code, notes, and snippets.

@ManuViola77
Created August 11, 2020 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ManuViola77/ebb7e47769a54b2fb6759eeefc912809 to your computer and use it in GitHub Desktop.
Save ManuViola77/ebb7e47769a54b2fb6759eeefc912809 to your computer and use it in GitHub Desktop.
Navigation helper
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