title: How to test a stub returning a promise in an async test?
body: <p>How can I test this in a async manner?</p>
  
  <pre><code>it('Should test something.', function (done) {
  
      var req = someRequest,
          mock = sinon.mock(response),
          stub = sinon.stub(someObject, 'method');
  
       // returns a promise
       stub.withArgs('foo').returns(Q.resolve(5));
  
       mock.expects('bar').once().withArgs(200);
  
       request(req, response);
  
       mock.verify();
  
  });
  </code></pre>
  
  <p>And here is the method to test.</p>
  
  <pre><code>var request = function (req, response) {
  
      ...
  
      someObject.method(someParameter)
          .then(function () {
              res.send(200);
          })
          .fail(function () {
              res.send(500);
          });
  
  };
  </code></pre>
  
  <p>As you can see I am using node.js, Q (for the promise), sinon for mocking and stubbing and mocha as the test environment. The test above fails because of the async behaviour from the request method and I don't know when to call done() in the test.</p>