Skip to content

Instantly share code, notes, and snippets.

@joebalancio
Created February 13, 2013 21:30
Show Gist options
  • Save joebalancio/4948500 to your computer and use it in GitHub Desktop.
Save joebalancio/4948500 to your computer and use it in GitHub Desktop.
Resolved issue of testing nested promises
Q = require('q')
sinon = require('sinon')
sinonChai = require('sinon-chai')
chai.use(sinonChai)
sinon.should()
describe 'testing promises', ->
aDeferred = Q.defer()
bDeferred = Q.defer()
moduleA =
asyncMethodA: ->
return aDeferred.promise
moduleB =
asyncMethodB: ->
return bDeferred.promise
it 'should pass', ->
sinon.spy moduleA, 'asyncMethodA'
sinon.spy moduleB, 'asyncMethodB'
aDeferred.resolve 'fooResolve'
bDeferred.resolve 'barResolve'
moduleA.asyncMethodA('foo')
.then (value) ->
console.log value
return moduleB.asyncMethodB('bar')
.then (value) ->
console.log value
.fail (err) ->
err
.done ->
moduleA.asyncMethodA.should.have.been.called
moduleB.asyncMethodB.should.have.been.called
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment