Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class myClass extends React.Component {
- ...
- closeModal = async () => {
- if (someCondition) {
- await myFunction1();
- } else {
- await myFunction2();
- }
- this.props.navigation.state.params.onGoBack();
- this.props.navigation.navigate('Main');
- };
- ...
- }
- const navigation = {
- navigate: jest.fn(),
- state: { params: { onGoBack: jest.fn() } },
- };
- const renderComponent = overrides => {
- props = {
- navigation,
- ...overrides,
- };
- return shallow(< myClass.wrappedComponent {...props} />);
- };
- describe('When the user presses the close icon', () => {
- it('should close the modal', () => {
- const component = renderComponent();
- const instance = component.instance();
- const spyCloseModal = jest.spyOn(instance, 'closeModal');
- component.instance().forceUpdate();
- component
- .find({ testID: 'close-icon' })
- .props()
- .onPress();
- expect(spyCloseModal).toHaveBeenCalled(); // this is passed
- expect(navigation.navigate).toHaveBeenCalled(); // this is not passed
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement