title: Vue-test-utils Mock fetch response from another component
body: <p>I'm trying to set up unit tests using <code>vue-test-utils</code> and <code>jest</code> on some Vue components that retrieve responses from another Vue component (ApiCalls.vue) that is in charge of making calls to a remote API using <code>fetch()</code>.
  The component that makes API calls returns objects of this type :</p>
  <pre class="lang-json prettyprint-override"><code>{
    status: &lt;fetch response status&gt;,
    body: &lt;fetch response body&gt;
  }
  </code></pre>
  <p>Component to be tested overview (<code>MyComponent.vue</code>) :</p>
  <pre class="lang-js prettyprint-override"><code>import ApiCalls from './ApiCalls.vue';
  
  export default {
    data() {
      return {
        resultsFromAPI: null
      }
    },
    mounted() {
      this.getSomeData();
    },
    methods: {
      async getSomeData() {
        const APIResponse = await ApiCalls.data().getSomeData();
        if (APIResponse.status === 200) {
          this.resultsFromAPI = APIResponse.body;
        }
      }
    }
  }
  </code></pre>
  <p>Test spec overview :</p>
  <pre class="lang-js prettyprint-override"><code>import { shallowMount } from '@vue/test-utils';
  import MyComponent      from './MyComponent.vue';
  
  const wrapper = shallowMount(MyComponent);
  
  test('check data from API', () =&gt; {
    expect(wrapper.vm.resultsFromAPI).toBe(&lt;stuff fromAPI&gt;);
  });
  </code></pre>
  <p>I tried to mock the function <code>getSomeData</code> like this :</p>
  <pre class="lang-js prettyprint-override"><code>wrapper.vm.getSomeData = jest.fn(() =&gt;
    Promise.resolve({
      json: () =&gt; Promise.resolve({status: 200, body: { result: 'blabla' }),
    })
  );
  </code></pre>
  <p>Or</p>
  <pre class="lang-js prettyprint-override"><code>const getSomeData = jest.fn(() =&gt;
    Promise.resolve({
      json: () =&gt; Promise.resolve({status: 200, body: { result: 'blabla' }),
    })
  );
  </code></pre>
  <p>But it doesn't works and I can't find any clue in the vue-test-utils nor jest config...
  Any help would be appreciated.</p>