Skip to content

Instantly share code, notes, and snippets.

@ManuViola77
Last active August 12, 2020 19:11
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/809d28c61fdad272d2ce1b3d3147bde5 to your computer and use it in GitHub Desktop.
Save ManuViola77/809d28c61fdad272d2ce1b3d3147bde5 to your computer and use it in GitHub Desktop.
MainScreen test
import {act, fireEvent, waitFor} from '@testing-library/react-native';
import {Alert} from 'react-native';
import AppStack from '../../src/navigators/AppStack';
import {renderWithNavigation} from '../extras/helpers';
describe('<MainScreen />', () => {
let wrapper;
beforeEach(() => {
wrapper = renderWithNavigation(AppStack);
});
it('should render the main screen', () => {
expect(wrapper.queryByTestId('MainScreen')).toBeTruthy();
});
it('should render the go to secondary screen button', () => {
expect(wrapper.queryByTestId('button-to-secondary-screen')).toBeTruthy();
});
describe('when go to secondary screen button is pressed', () => {
it('it should render SecondaryScreen ', async () => {
act(() => {
fireEvent.press(wrapper.queryByTestId('button-to-secondary-screen'));
});
await waitFor(() =>
expect(wrapper.queryByTestId('SecondaryScreen')).toBeTruthy(),
);
});
});
it('should render the alert button', () => {
expect(wrapper.queryByTestId('alert-button')).toBeTruthy();
});
describe('when take alert button is pressed', () => {
it('it should render an Alert ', async () => {
const alertSpy = jest.spyOn(Alert, 'alert');
act(() => {
fireEvent.press(wrapper.queryByTestId('alert-button'));
});
await waitFor(() => expect(alertSpy).toHaveBeenCalled());
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment