Hey guys!
I'm facing a problem with an API who gets a response before the code ends.
I'm using mocha to run tests and the code and its test is something like that:
function(req, res) {
anything(arg, function() {
stubbedFunction();
})
return res.send(200).end();
}
describe('whatever', function() {
it('just do it', function(done) {
request(app)
.post('/')
.end(function(err, response) {
assert.isNull(err);
done();
});
});
});
The problem, as you may see, is that the stubbedFunction will probably be called after the callback to the test request.
So... I was thinking if there is any way to wait my stub to be called and then finish my test... something like that:
sinon.stub(jsFile, 'stubbedFunction').waitForCall().then(done);
Thanks!!