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 callFn
is 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.