title: How to mock AxiosInstance with jest
body: <p>I want to unit test a class which use axios to send post request to another server but I keep getting the following error:</p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'post' of undefined</p>
  </blockquote>
  
  <p>Here are my codes</p>
  
  <pre><code>//PostController.ts
  const axios = require('axios').default;
  
  export class PostController {
    async sendPostRequest(): Promise&lt;boolean&gt; {
      //type AxiosInstance
      const instance = axios.create({
        baseURL: 'http://example.com',
        timeout: 60 * 3 * 1000, //milliseconds. 3 minutes. 
        headers: {'X-Custom-Header': 'secret-key'}
      });
  
      const {status} = await instance.post('/submitUsername', {username: 'nux'});
  
      return status === 200;
    }
  }
  </code></pre>
  
  <p>And this is how my test look like:</p>
  
  <pre><code>//PostController.test.ts
  import {PostController} from './ProviderController';
  import axios from 'axios';
  
  const mockedAxios = axios as jest.Mocked&lt;typeof axios&gt;;
  
  jest.mock('axios');
  
  describe('PostController', () =&gt; {
    it('should send post request and return 200', async () =&gt; {
      const controller = new PostController();
      const response = {status: 200};
  
      mockedAxios.post.mockResolvedValue(response);
      const result = await controller.sendPostRequest();
  
      expect(mockedAxios.post).toHaveBeenCalled();
      expect(result).toBeTruthy();
    });
  });
  </code></pre>
  
  <p>What could be wrong here? Any help will be appreciated.</p>