title: Getting undefined when I return some response from mocked axios call using jest
body: <p>I'm trying to mock axios call and verify the response, but when I log the response from mocked axios call, I'm getting <code>undefined</code>. Anyone have any ideas why? </p>
  
  <p>users.js</p>
  
  <pre><code>import axios from 'axios';
  
  export default class MyClass{
     constructor(config){
        this.config = config;
     }
  
     async getUsers(url, params, successHandler, errorHandler) {
        return axios.post(url, params)
               .then(resp =&gt; this.handleAPIResponse.call(this, resp, successHandler, errorHandler))
               .catch(error =&gt; errorHandler);
     }
  }
  </code></pre>
  
  <p>users.test.js</p>
  
  <pre><code>import MyClass from './mycode.js';
  import axios from 'axios';
  
  jest.mock('axios');
  
  beforeEach(() =&gt; {
    myClass = new MyClass({ env: 'prod' });
  });
  
  afterEach(() =&gt; {
    jest.clearAllMocks();
  });
  
  const mockResponseData = jest.fn((success, payload) =&gt; {
    return {
      data: {
        result: {
          success,
          payload
        }
      }
    };
  });
  
  test('should return all the users', async () =&gt; {
     const successHandler = jest.fn();
     const errorHandler = jest.fn();
     const users = mockResponseData(true, ['John Doe', 'Charles']);
  
     axios.post.mockImplementationOnce(() =&gt; {
       return Promise.resolve(users);
     });
  
     const response = await myClass.getUsers('url', {}, successHandler, errorHandler);
     console.log(response);  // This logs undefined
     expect(successHandler).toHaveBeenCalledTimes(1);
  });
  </code></pre>
  
  <p>Also, I just want to clear it out that I've a <strong>mocks</strong> folder just under my src directory inside which I've a file named axios.js where I've mocked axios' post method. It looks like this:</p>
  
  <pre><code>export default {
    post: jest.fn(() =&gt; Promise.resolve({ data: {} }))
  };
  </code></pre>