Skip to content

Instantly share code, notes, and snippets.

@Luke-Rogerson
Created September 19, 2020 15:02
Show Gist options
  • Save Luke-Rogerson/7660441ab2b4624c233ab480d67798db to your computer and use it in GitHub Desktop.
Save Luke-Rogerson/7660441ab2b4624c233ab480d67798db to your computer and use it in GitHub Desktop.
const navigateToProfile = jest.fn()
jest.mock('@react-navigation/native', () => {
const module = jest.requireActual('@react-navigation/native')
return {
...module,
useNavigation: {
navigate: () => ({
navigate: navigateToProfile,
}),
},
}
})
test('it should navigate to user profile on press', () => {
const userId = 'abc123'
const { getByTestId } = render(<ComponentWithMockedNavigator userId={userId} />)
const userAvatar = getByTestId('avatar')
fireEvent.press(userAvatar)
expect(navigateToProfile).toHaveBeenCalledTimes(1)
expect(navigateToProfile).toHaveBeenCalledWith({ userId })
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment