Skip to content

Instantly share code, notes, and snippets.

@ManuViola77
Last active August 12, 2020 19:09
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/84c055e49f70d48423d5db302bb2fefd to your computer and use it in GitHub Desktop.
Save ManuViola77/84c055e49f70d48423d5db302bb2fefd to your computer and use it in GitHub Desktop.
SecondaryScreen test
import {act, fireEvent, waitFor} from '@testing-library/react-native';
import {screenParameters} from '../extras/data';
import {renderWithNavigation} from '../extras/helpers';
import SecondaryScreen from '../../src/screens/SecondaryScreen';
import MainScreen from '../../src/screens/MainScreen';
describe('<SecondaryScreen />', () => {
let wrapper;
const otherComponents = [{name: 'MainScreen', component: MainScreen}];
beforeEach(() => {
wrapper = renderWithNavigation(SecondaryScreen, {
otherComponents,
screenConfig: {
initialParams: screenParameters,
},
});
});
it('should render SecondaryScreen', () => {
expect(wrapper.queryByTestId('SecondaryScreen')).toBeTruthy();
});
it('should render the go back button', () => {
expect(wrapper.queryByTestId('back-button')).toBeTruthy();
});
describe('when go back button is pressed', () => {
it('it should render MainScreen ', async () => {
act(() => {
fireEvent.press(wrapper.queryByTestId('back-button'));
});
await waitFor(() =>
expect(wrapper.queryByTestId('MainScreen')).toBeTruthy(),
);
});
});
it('should render title', () => {
expect(wrapper.queryByTestId('title')).toBeTruthy();
});
it('should render param one', () => {
expect(wrapper.queryByTestId('param-one')).toBeTruthy();
});
it('should render param two content', () => {
expect(wrapper.queryByTestId('param-two-content')).toBeTruthy();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment