title: Mock HTTP fetch in sinon
body: <p>I am trying to mock HTTP fetch in jsfiddle. I am not sure what I do wrong that makes the result not to be equal to the mock one.</p>
  
  <p>Here is my sample code: (You can see the logs in the browser console.)</p>
  
  <p><a href="http://jsfiddle.net/maryam_saeidi/yredb06m/7/" rel="nofollow noreferrer">http://jsfiddle.net/maryam_saeidi/yredb06m/7/</a></p>
  
  <pre><code>async function getUser(userId) {    
          var user = await fetch("http://website/api/users/" + userId);
      return user.json();
  } 
  
  mocha.setup("bdd");
  chai.should();
  var assert = chai.assert,
          expect = chai.expect;
  
  describe('getUser()', () =&gt; {
      let server;
  
      beforeEach(function() {
      server = sinon.fakeServer.create();
    });
  
    afterEach(function () {
      server.restore();
    });
  
    it('should return a user.', async () =&gt; {
      const response = await getUser(1);
      console.log("response:", response);
    });
  
    it('should return a user object', async () =&gt; {
      const userId = 10;
      server.respondWith("GET", "http://website/api/users/" + userId,[200, { "Content-Type": "application/json" },
                          '{ "id": "1", "username": "John", "avatar_url": "A_URL" }']);
      const response = getUser(userId);
      server.respond();
      response.then(function(result){
        console.log("result:",result); //The code doesn't get here
        result.should.deep.equal({ "id": "1", "username": "John", "avatar_url": "A_URL" });
        });
    });
  
  });
  
  mocha.run();
  </code></pre>