Skip to content

Instantly share code, notes, and snippets.

@johnmarinelli
Last active August 17, 2021 19:25
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johnmarinelli/25836da38a60edb6723f233d7ef20a94 to your computer and use it in GitHub Desktop.
Save johnmarinelli/25836da38a60edb6723f233d7ef20a94 to your computer and use it in GitHub Desktop.
Cavy + React Navigation (TabNavigator)
import { TabNavigator } from 'react-navigation'
import Ionicons from 'react-native-vector-icons/Ionicons'
import { hook } from 'cavy'
class Icon extends Component {
render() {
const { navigation, generateTestHook, routeName... } = this.props
return <Ionicons ref={generateTestHook(`Navigation.${routeName}`)} onPress={() => navigation.navigate(routeName)} .../>
}
}
const TestableIcon = hook(Icon)
const AppNavigator = TabNavigator(
...,
navigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state
return <TestableIcon navigation={navigation} routeName={routeName} />
}
})
}
)
const AppSpec = spec => {
spec.describe('Smoke test', () => {
spec.it('navigates to Profile screen from the Home screen', async () => {
await spec.press('Navigation.Profile')
await spec.exists(/* assert some component that you should see on 'Profile' exists */)
})
})
}
export default AppSpec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment