title: How to test async function with spyOn?
body: <p>I am trying to test an async function in a react native app.</p>
  
  <pre><code>class myClass extends React.Component {
  
    ...
  
    closeModal = async () =&gt; {
  
      if (someCondition) {
        await myFunction1();
      } else {
        await myFunction2();
      }
  
      this.props.navigation.state.params.onGoBack();
      this.props.navigation.navigate('Main');
    };
  
    ...
  
  }
  </code></pre>
  
  <p>This is my test:</p>
  
  <pre><code>const navigation = {
    navigate: jest.fn(),
    state: { params: { onGoBack: jest.fn() } },
  };
  
  const renderComponent = overrides =&gt; {
    props = {
      navigation,
      ...overrides,
    };
  
    return shallow(&lt; myClass.wrappedComponent {...props} /&gt;);
  };
  
  
  describe('When the user presses the close icon', () =&gt; {
      it('should close the modal', () =&gt; {
        const wrapper = renderComponent();
        const instance = wrapper.instance();
        const spyCloseModal = jest.spyOn(instance, 'closeModal');
        instance().forceUpdate();
        component
          .find({ testID: 'close-icon' })
          .props()
          .onPress();
        expect(spyCloseModal).toHaveBeenCalled(); // this is passed
        expect(navigation.navigate).toHaveBeenCalled(); // this is not passed
      });
  });
  </code></pre>
  
  <p>It looks like it gets stuck on the await calls. If I remove the await calls then it passes. Someone mentioned in another post to use <code>.and.callThrough</code> after spyOn but it gives me this error</p>
  
  <blockquote>
    <p>Cannot read property 'callThrough' of undefined</p>
  </blockquote>