title: How to resolve axios mocking errors using JEST and REACT
body: <p>Have created unit test cases using axios mock approach and do see below console errors. Have tried many approaches but none resolved the problem. Very new to REACT/JEST community, but trying best to resolve this.</p>
  
  <p><strong>Expectation:</strong></p>
  
  <ol>
  <li>All test cases including success, error scenarios should be 100% covered and should pass with no warnings/errors.</li>
  <li>Response should be tested with empty results list and as well with non-empty results list.</li>
  <li>Error scenarios due to timeout/network should also be handled.</li>
  </ol>
  
  <p><strong>Errors:</strong></p>
  
  <pre><code>
  Expected: undefined
  Received: {"results": []}
  
  (node:76675) UnhandledPromiseRejectionWarning: 
  Unhandled promise rejection. This error originated 
  either by throwing inside of an async function without a catch block, 
  or by rejecting a promise which was not handled with .catch(). 
  (rejection id: 1)
  
  (node:76675) [DEP0018] DeprecationWarning: Unhandled promise rejections 
  are deprecated. In the future, promise rejections that are not handled will 
  terminate the Node.js process with a non-zero exit code.
  </code></pre>
  
  <p>What I tried:</p>
  
  <p><strong>index.js</strong></p>
  
  <pre><code>export default getAreas = area =&gt; axios.get(`/test/areas/${area}`);
  </code></pre>
  
  <p><strong>__mocks__/axios.js</strong></p>
  
  <pre><code>const axiosMocked = {
    get: jest.fn(() =&gt; Promise.resolve({ results: [] }))
  };
  export default axiosMocked;
  </code></pre>
  
  <p><strong>__tests__/index.test.js</strong></p>
  
  <pre><code>import mockAxios from 'axios';
  import getAreas from '../index';
  
  afterEach(() =&gt; {
    jest.clearAllMocks();
  });
  
  it('fetches results from api', () =&gt; {
    mockAxios.get.mockImplementationOnce(() =&gt; Promise.resolve({ results: [] }));
    getAreas('atl').then(response =&gt; {
      expect(response).toEqual();
    });
    expect(mockAxios.get).toHaveBeenCalledTimes(1);
    expect(mockAxios.get).toHaveBeenCalledWith('/test/areas/atl');
  });
  </code></pre>