Skip to content

Instantly share code, notes, and snippets.

@alonronin
Created June 23, 2015 10:40
Show Gist options
  • Save alonronin/dce0e2328bf126b40d99 to your computer and use it in GitHub Desktop.
Save alonronin/dce0e2328bf126b40d99 to your computer and use it in GitHub Desktop.
mocking promises $q.all using $scope.$apply()
+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);
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