Created
February 13, 2013 21:30
-
-
Save joebalancio/4948500 to your computer and use it in GitHub Desktop.
Resolved issue of testing nested promises
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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