title: Issues mocking return value of Axios post call for unit test
body: <p>Trying to mock an Axios call to <em>unit test</em> a token response from our identity software. Axios is not getting called at all and because of that my return is always undefined.</p>
  <p>I've tried changing up Axios call to axios.post and changing the way I've mocked this more times then I can count. I don't believe like I should have to install another mocking framework just for Axios to mock this one function.</p>
  <p>Implementation:</p>
  <pre><code>async getAuthToken() {        
      const oauthUrl = process.env.OAUTHURL;
      const oauthAudience = process.env.OAUTHAudience;
      const oauthUsername = process.env.OAUTHUSERNAME;
      const oauthPassword = process.env.OAUTHPASSWORD;
      
      let urlForAuth = oauthUrl
      urlForAuth = urlForAuth + '/as/token.oauth2?';
      urlForAuth = urlForAuth + 'grant_type=client_credentials';
      urlForAuth = urlForAuth + '&amp;aud=' + oauthAudience + '/';
      urlForAuth = urlForAuth + '&amp;scope=' + oauthAudience + '/.read';
      
      const options = {
          method: 'POST',
          url: urlForAuth,
          headers: {
              'Authorization': &quot;Basic &quot; + Buffer.from(oauthUsername + &quot;:&quot; + oauthPassword).toString(&quot;base64&quot;)
          },
          responseType: 'json'
      };
      
      try{
          let response = await axios(options); 
          return response.data.access_token;
      }
      catch(e){
          console.log(e);
          throw e;
      }       
  }
  </code></pre>
  <p>Test Case:</p>
  <pre><code>test('token Is Returned', async () =&gt; {
      expect.hasAssertions();
  
      let Response = `{
              &quot;access_token&quot;: &quot;thisisatoken&quot;,
              &quot;token_type&quot;: &quot;Bearer&quot;,
              &quot;expires_in&quot;: 3599
          }`;
  
      axios = jest.fn(() =&gt; Promise.resolve());
  
      axios.mockImplementationOnce(() =&gt;
          Promise.resolve({
              data: Response
          })
      );            
      
      let response = await AuthService.getAuthToken();
  
      expect(axios).toHaveBeenCalledTimes(1);
      expect(response).toEqual(&quot;thisisatoken&quot;);  
  });
  </code></pre>
  <p>The error I am getting is</p>
  <blockquote>
  <p>Expected mock function to have been called one time, but it was called zero times.</p>
  </blockquote>
  <p>When I debug the data element on the response contains the following:</p>
  <blockquote>
  <p>data:&quot;Copyright (c) 2019 Next Small Things\n&quot;</p>
  </blockquote>
  <p>That is no where in my code. help.</p>