Trying to test a promise-based service that does something like this:
load : function(){
var deferred = $q.defer();
deferred.resolve();
return deferred.promise;
}
When trying to test this in Karma + Jasmine 2.0, I try to use my callbacks (), but it always runs out of time and does not resolve the promise.
beforeEach(inject(function ($injector) {
service = $injector.get('myService');
$window = $injector.get("$window");
$rootScope = $injector.get('$rootScope');
}));
describe('Call load', function () {
it('resolves its promise', function (done) {
service.load().then(function(){
expect(something).not.toBe(undefined);
done();
});
});
});
From Jasmines docs, this is how I am, although you should use done () along with asynchronous code, but the problem seems to be that the promise never solves
source
share