Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. class myClass extends React.Component {
  2.  
  3. ...
  4.  
  5. closeModal = async () => {
  6.  
  7. if (someCondition) {
  8. await myFunction1();
  9. } else {
  10. await myFunction2();
  11. }
  12.  
  13. this.props.navigation.state.params.onGoBack();
  14. this.props.navigation.navigate('Main');
  15. };
  16.  
  17. ...
  18.  
  19. }
  20.  
  21. const navigation = {
  22. navigate: jest.fn(),
  23. state: { params: { onGoBack: jest.fn() } },
  24. };
  25.  
  26. const renderComponent = overrides => {
  27. props = {
  28. navigation,
  29. ...overrides,
  30. };
  31.  
  32. return shallow(< myClass.wrappedComponent {...props} />);
  33. };
  34.  
  35.  
  36. describe('When the user presses the close icon', () => {
  37. it('should close the modal', () => {
  38. const component = renderComponent();
  39. const instance = component.instance();
  40. const spyCloseModal = jest.spyOn(instance, 'closeModal');
  41. component.instance().forceUpdate();
  42. component
  43. .find({ testID: 'close-icon' })
  44. .props()
  45. .onPress();
  46. expect(spyCloseModal).toHaveBeenCalled(); // this is passed
  47. expect(navigation.navigate).toHaveBeenCalled(); // this is not passed
  48. });
  49. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement