Sinon doesn't work with Q promises

203 Views Asked by At

I have been using sinon for very long time and it worked perfectly. But now we are started to use Q promises, looks like things are breaking with sinon spies.

For example:

var spy = sandbox.spy(someApi,"callFn")
// success: return a promise fulfilled with `5`:
someStub.withArgs("foo").returns(Q.resolve(5));

I could able to do this, which in turn resolves the promise. I could able to see that the then block of promise is executing by adding an console.log statement:

promise.then(function(){
  console.log("comes here") // <---- gets printed
  someApi.callFn() // <--- spies on this are failing
})

Even though the callFnis called, spy still says callCount is 0. I'm really not sure, why sinon wasn't able to spy an function which is called inside the promise then block.

Am I missing something here? Kindly let me know in order to fix my problem.

0

There are 0 best solutions below