title: JS Jest Mocking - expected received undefined error
body: <p>I have code that uses <code>axios</code> to get some data. </p>
  
  <pre><code>const axios = require('axios');
  
  class Users {
       static async all() {
          let res = await axios.get('http://localhost:3000/users');
          return res.data;
        }
  }
  
  module.exports = Users;
  </code></pre>
  
  <p>This should be tested with Jest framework.</p>
  
  <pre><code>const axios = require('axios');
  const Users = require('./users');
  
  jest.mock('axios');
  
  test('should fetch users', () =&gt; {
  
      const users = [{
          "id": 1,
          "first_name": "Robert",
          "last_name": "Schwartz",
          "email": "rob23@gmail.com"
      }, {
          "id": 2,
          "first_name": "Lucy",
          "last_name": "Ballmer",
          "email": "lucyb56@gmail.com"
      }];
  
      const resp = { data : users };
  
      // axios.get.mockResolvedValue(resp);
      axios.get.mockImplementation(() =&gt; Promise.resolve(resp));
  
      // console.log(resp.data);
  
      return Users.all().then(resp =&gt; expect(resp.data).toEqual(users));
  });
  </code></pre>
  
  <p>The test fails with </p>
  
  <pre><code>expect(received).toEqual(expected)
  
  Expected: [{"email": "rob23@gmail.com", "first_name": "Robert", "id": 1, "last_name": "Schwartz"}, {"email": "lucyb56@gmail.com", "first_name": "Lucy", "id": 2, "last_name": "Ballmer"}]
  Received: undefined
  </code></pre>
  
  <p>The real data is:</p>
  
  <pre><code>{ "users": [
      {
          "id": 1,
          "first_name": "Robert",
          "last_name": "Schwartz",
          "email": "rob23@gmail.com"
      },
      {
          "id": 2,
          "first_name": "Lucy",
          "last_name": "Ballmer",
          "email": "lucyb56@gmail.com"
      }
  ...
  ]
  }
  </code></pre>
  
  <p>I was thinking maybe this is a problem with named/not named JSON arrays.
  How to fix it?</p>