title: How to mock an axios request using sinon modules
body: <p>There seems to be so many different ways to do this, but I am trying to use just sinon, sinon-test, chai/mocha, axios, httpmock modules. I am not able to successfully mock a GET call made using axios. I want to be able to mock the response from that axios call so the unit test won't actually have to make the external API request.</p>
  
  <p>I've tried setting up a basic unit test by creating a sandbox, and using sinon stub to set up a GET call and specify the expected response. I'm unfamiliar with JavaScript and NodeJS.</p>
  
  <pre><code>// Main class (filename: info.js)
  
  function GetInfo(req, res) {
      axios.get(&lt;url&gt;).then(z =&gt; res.send(z.data));
  }
  
  // Test class (filename: info.test.js)
  
  it ("should return info", () =&gt; {
      const expectedResponse = "hello!";
      const res = sinon.spy();
      const aStub = sinon.stub(axios, "get").resolves(Promise.resolve(expectedResponse));
  
      const req = httpMock.createRequest({method:"get", url:"/GetInfo"});
  
      info.GetInfo(req, res);
  
      // At this point, I need to evaluate the response received (which should be expectedResponse)
      assert(res.data, expectedResponse); // data is undefined, res.status is also undefined
  
      // How do I read the response received?
  
  });
  </code></pre>
  
  <p>I need to know how to read the response that is supposed to be sent back (if it is being captured in the first place by sinon).</p>