I have this piece of CoffeeScript code in one of my Backbone views:
myMethod: ->
# some code here
$.when(
# ...
).done(
@myCallback
)
and I wanna test that myCallback is called in the done block.
I'm not sure how to do this in Mocha.js + Sinon.js. I was able to spy on jquery and check that the when method is called:
spy = sinon.spy($, 'when')
@view.myMethod()
spy.called.should.be.true
spy.restore()
But I can't do the same with the done block because, if I have unterstood it right, it's related to the deferred object returned by the when method.
I also tried something like this:
# NOT WORKING CODE
stub = sinon.stub($.Deferred(), 'done').returns
myCallback: sinon.stub()
@view.myMethod()
stub.called.should.be.true
stub.restore()
but still getting:
expected false to be true
Any ideas? :)