Created
June 23, 2015 10:40
-
-
Save alonronin/dce0e2328bf126b40d99 to your computer and use it in GitHub Desktop.
mocking promises $q.all using $scope.$apply()
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
+function(angular){ | |
'use strict'; | |
angular.module('app.services') | |
.service('MyService', function($q){ | |
var self = this; | |
var a = function(){ return $q.when({}) }; | |
var b = function(){ return $q.when({}) }; | |
self.promiseAll = function(){ | |
$q.all([ | |
a(), | |
b() | |
]) | |
.then(function(){ | |
self.bar = 'foo'; | |
}) | |
} | |
}) | |
; | |
}(angular); |
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
describe('Service', function () { | |
beforeEach(module('app.services')); | |
beforeEach(inject(function (_MyService_, _$rootScope_) { | |
this.Service = _MyService_; | |
this.$scope = _$rootScope_.$new(); | |
})); | |
it('should have a service', function () { | |
expect(this.Service).not.to.be.null; | |
}); | |
it('should resolve $q.all', function () { | |
this.Service.promiseAll(); | |
this.$scope.$apply(); | |
expect(this.Service.bar).to.be.equals('foo'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment