Skip to content

Instantly share code, notes, and snippets.

@mainyaa
Last active December 30, 2015 08:29
Show Gist options
  • Save mainyaa/7802630 to your computer and use it in GitHub Desktop.
Save mainyaa/7802630 to your computer and use it in GitHub Desktop.
unit testing $q.all
'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