Skip to content

Instantly share code, notes, and snippets.

@Fred-Reis
Created July 14, 2020 00:58
Show Gist options
  • Save Fred-Reis/b4ec44b51f0eca40b9b706041bd41453 to your computer and use it in GitHub Desktop.
Save Fred-Reis/b4ec44b51f0eca40b9b706041bd41453 to your computer and use it in GitHub Desktop.
import React from 'react';
import { render, fireEvent } from 'react-native-testing-library';
import Home from '../../pages/Home';
const mockedNavigation = jest.fn();
jest.mock('@react-navigation/native', () => {
return {
useNavigation: () => ({
navigate: mockedNavigation,
}),
};
});
describe('Home page', () => {
beforeEach(() => {
mockedNavigation.mockClear();
});
it('should be able to open QRcode scanner page', async () => {
const { getByTestId } = render(<Home />);
fireEvent.press(getByTestId('open-qrcode-test'));
expect(mockedNavigation).toHaveBeenCalledWith('QRcodeScanner');
});
});
@Fred-Reis
Copy link
Author

Very useful

@Cleversou1983
Copy link

Thanks man!

@brunoluisv
Copy link

thanks man, very helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment