Last active
December 30, 2015 08:29
-
-
Save mainyaa/7802630 to your computer and use it in GitHub Desktop.
unit testing $q.all
This file contains 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
'use strict' | |
# dependencies angularjs, karma, karma-mocha, mocha, chai | |
describe 'Unit: $q.all', () -> | |
it 'should simulate promise', inject ($q, $rootScope) -> | |
deferred1 = $q.defer() | |
promise1 = deferred1.promise | |
deferred2 = $q.defer() | |
promise2 = deferred2.promise | |
resolvedValue = undefined | |
alldone = false | |
$q.all([promise1, promise2]).then (value) -> | |
alldone = true | |
console.log "alldone" | |
promise1.then (value) -> | |
resolvedValue = value | |
promise2.then (value) -> | |
resolvedValue = value | |
expect(resolvedValue).to.be.undefined | |
expect(alldone).to.equal(false) | |
deferred1.resolve(123) | |
expect(alldone).to.equal(false) | |
deferred2.resolve(123) | |
expect(resolvedValue).to.be.undefined | |
$rootScope.$apply() | |
expect(resolvedValue).to.equal(123) | |
expect(alldone).to.equal(true) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment