Given the following service:
angular.module('app', [])
.service('promisey', function ($q) {
this.cakey = function () {
return $q.when('brownie')
}
this.fruity = function () {
return $q.when(Promise.resolve('apple'))
}
})
... and the following test:
var self = this
describe('when', function () {
var promisey
var $rootScope
beforeEach(module('app'))
beforeEach(inject(function(_$rootScope_, _promisey_) {
promisey = _promisey_
$rootScope = _$rootScope_
}))
it('should give cakes', function (done) {
promisey.cakey()
.then(function (cake) {
expect(cake).toBe('brownie')
})
.catch(self.fail.bind())
.finally(done)
$rootScope.$apply()
})
it('should give fruit', function (done) {
promisey.fruity()
.then(function (cake) {
expect(cake).toBe('apple')
})
.catch(self.fail.bind())
.finally(done)
$rootScope.$apply()
})
})
... when ngMockreceived, promisey.fruity()will never be allowed. If I do not send ngMock(and the handle itself angular.injector), the test will be resolved, as expected. Why is this?
An abbreviated test case for this question can be found at tlvince / q-when-reduced-test-case .
source
share