Last active
August 12, 2020 19:11
-
-
Save ManuViola77/809d28c61fdad272d2ce1b3d3147bde5 to your computer and use it in GitHub Desktop.
MainScreen test
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 {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