title: How to mock Axios as default export with Jest
body: <p>How do I mock <code>axios</code> that export as default function?</p>
  
  <p>I have the api helper that generalizes api request with <code>axios()</code></p>
  
  <p><strong>api.js</strong></p>
  
  <pre><code>export const callApi = (endpoint, method, data = {}) =&gt; {
  
    return axios({
      url: endpoint,
      method,
      data
    })
    .then((response) =&gt; // handle response)
    .catch((error) =&gt; // handle error)
  };
  </code></pre>
  
  <p><strong>api.spec.js</strong></p>
  
  <pre><code>import axios from 'axios';
  import { callApi } from './api';
  
  describe('callApi()', () =&gt; {
    it('calls `axios()` with `endpoint`, `method` and `body`', () =&gt; {
  
      // mock axios()
      jest.spyOn(axios, 'default');
  
      const endpoint = '/endpoint';
      const method = 'post';
      const data = { foo: 'bar' };
  
      // call function
      callApi(endpoint, method, data);
  
      // assert axios()
      expect(axios.default).toBeCalledWith({ url: endpoint, method, data});
    });
  }); 
  </code></pre>
  
  <p><strong>result</strong></p>
  
  <pre><code>Expected mock function to have been called with:
    [{"data": {"foo": "bar"}, "method": "post", "url": "/endpoint"}]
  But it was not called.
  </code></pre>
  
  <p>The call works fine if I mock <code>axios.get()</code> or other methods, but not for just <code>axios()</code>. I don't want to change the definition of the <code>callApi()</code> function.</p>
  
  <p>How do I mock default <code>axios()</code>? What did I miss?</p>