title: _axios.default.post.mockImplementationOnce is not a function VuesJS
body: <p>I try to test my API Call.
  I'm using:</p>
  <ol>
  <li>VueJS</li>
  <li>Jest</li>
  <li>Axios</li>
  </ol>
  <p>I received the error: &quot;_axios.default.post.mockImplementationOnce is not a function&quot; when I run this test:</p>
  <pre><code>import axios from 'axios'
  
  let url = ''
  let body = {}
  
  jest.mock(&quot;axios&quot;, () =&gt; ({
    //__esModule: true,
    post: (_url, _body) =&gt; { 
      return new Promise((resolve) =&gt; {
        url = _url
        body = _body
        resolve(true)
      })
    }
  }))
  
  //axios.mockResolvedValue();
  
  describe('getGameList', () =&gt; {
    test('Success: should return the game list of the user and update gameList in the store', async () =&gt; {
      
      const response = {
        data: [ 
          { id:1, name:&quot;game_name1&quot; },
          { id:2, name:&quot;game_name2&quot; }
        ]
      };
  
      //axios.post.mockResolvedValue(response);
      //OR
      axios.post.mockImplementationOnce(() =&gt; Promise.resolve(response));
  
      expect(url).toBe(&quot;api/game_list_of_user&quot;)
      expect(body).toStrictEqual({&quot;user_id&quot;: 1})
  
    });
  
  });
  </code></pre>
  <p>Any clue ?</p>
  <p><strong>Edit 1</strong>: Following the help of tmhao2005:</p>
  <pre><code>jest.mock(&quot;axios&quot;, () =&gt; ({
    post: jest.fn((_url, _body) =&gt; { 
        url = _url
        body = _body
        return Promise.resolve();
      }),
    create: jest.fn(function () {
        return this;
    })
  }))
  
  describe('getGameList', () =&gt; {
    test('Success: should return the game list of the user and update gameList in the store', async () =&gt; {
      
      const url = &quot;api/game_list_of_user&quot;;
      const body = {
        &quot;user_id&quot;: 1
      };   
      const response = {
        data: [ 
          { id:1, name:&quot;game_name1&quot; },
          { id:2, name:&quot;game_name2&quot; }
        ]
      };
      axios.post.mockResolvedValue(response); //OR axios.post.mockImplementationOnce(() =&gt; Promise.resolve(response));
  
      expect(url).toBe(&quot;api/game_list_of_user&quot;)
      expect(body).toStrictEqual({&quot;user_id&quot;: 1})
  
      expect(axios.post).toHaveBeenCalledTimes(1);
  
    });
  
  });
  </code></pre>
  <p>But I still have that problem:
  <a href="https://i.stack.imgur.com/1AyyW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1AyyW.png" alt="enter image description here" /></a></p>
  <p>It looks like my mock axios is not called. the toHaveBeenCalledTimes method is the correct method to call ?</p>
  <p><strong>Edit 2</strong>:
  I called my action and try to mock my context.</p>
  <pre><code>let url = ''
  let body = {}
  
  jest.mock(&quot;axios&quot;, () =&gt; ({
    post: jest.fn((_url, _body) =&gt; { 
      return new Promise((resolve) =&gt; {
        url = _url
        body = _body
        resolve(true)
      })
    })
  }))
  
  //https://medium.com/techfides/a-beginner-friendly-guide-to-unit-testing-the-vue-js-application-28fc049d0c78
  //https://www.robinwieruch.de/axios-jest
  //https://lmiller1990.github.io/vue-testing-handbook/vuex-actions.html#testing-actions
  describe('getGameList', () =&gt; {
    test('Success: should return the game list of the user and update gameList in the store', async () =&gt; {
      //const commit = jest.fn()
      const MockContext = jest.fn(() =&gt; {
        let context= {
          state: {
            user: {
              id:1
            }
          }
        }
        return context
      });
      const response = {
        data: [ 
          { id:1, name:&quot;game_name1&quot; },
          { id:2, name:&quot;game_name2&quot; }
        ]
      };
  
      axios.post.mockResolvedValue(response); //OR axios.post.mockImplementationOnce(() =&gt; Promise.resolve(response));
  
      await actions.getGameList(axios.post, MockContext)
      expect(url).toBe(&quot;api/game_list_of_user&quot;)
      expect(body).toStrictEqual({&quot;user_id&quot;: 1})
  
      expect(axios.post).toHaveBeenCalledTimes(1)
      //expect(commit).toHaveBeenCalledWith(mutations.UpdateGameList, true)
    });
  
    test('Error: an error occurred', () =&gt; {
      const errorMessage = 'Error';
      axios.post.mockImplementationOnce(() =&gt;
        Promise.reject(new Error(errorMessage))
      );
    });
  
  });
  </code></pre>
  <p>I have this error now:
  <a href="https://i.stack.imgur.com/AqgSo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AqgSo.png" alt="enter image description here" /></a></p>