Last active
August 17, 2021 19:25
-
-
Save johnmarinelli/25836da38a60edb6723f233d7ef20a94 to your computer and use it in GitHub Desktop.
Cavy + React Navigation (TabNavigator)
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 { 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} /> | |
} | |
}) | |
} | |
) |
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
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