Reputation: 1071
In this plunk I have an Angular service that is tested by a Jasmine test. The test apparently cannot find the service, I get
Error: [$injector:unpr] http://errors.angularjs.org/1.6.1/$injector/unpr?p0=UtilsProvider%20%3C-%20Utils
and also
Error: Declaration Location
What's the problem here?
Javascript:
var app = angular.module("app", [])
app.service('Utils', function(){
this.sum = function(a, b) {
return a + b;
};
});
describe("Testing Service Utils", function() {
beforeEach(function() {
angular.module("app");
});
it('should sum',
inject(function(Utils) {
expect(Utils.sum(1,2)).to.equal(3);
}));
});
Upvotes: 1
Views: 212
Reputation: 164744
Two problems...
In order to register module configurations for testing, you need to use angular.mock.module
beforeEach(angular.mock.module('app'))
// or simply beforeEach(module('app'))
The equality assertion is toEqual
, not to.equal
expect(Utils.sum(1,2)).toEqual(3)
http://plnkr.co/edit/UZfKILseNklw2MgO2l8c?p=preview
Upvotes: 1