Reputation: 91620
I have a pretty simply filter which builds URLs for my templates:
angular.module('deAdmin.filters.shiurViewLink', []).filter('shiurViewLink', ['configService', function(configService) {
return function(shiur) {
if (shiur == null)
return "#";
return configService.getAppRoot() + "/shiurim/" + shiur.id + "/";
}
}]);
The referenced configService
:
angular.module('deAdmin.services.configService', []).factory('configService', [function() {
var service = {};
service.getAppRoot = function() {
return "/admin";
};
service.getStaticPrefix = function() {
return "/static/admin";
}
return service;
}]);
Here is my test for the filter:
'use strict';
describe('shiurViewLink', function() {
var $filter, filter;
beforeEach(function() {
module('deAdmin.filters.shiurViewLink');
inject(function($injector) {
$filter = $injector.get('$filter');
filter = $filter('shiurViewLink');
});
});
it("should properly generate the shiur view link", function() {
expect(filter({ id: "abcdefg" })).toBe('/admin/');
});
});
I'm seeing the following error in Karma/Jasmine test run:
Error: [$injector:unpr] Unknown provider: configServiceProvider <- configService <- shiurViewLinkFilter
http://errors.angularjs.org/1.2.4/$injector/unpr?p0=configServiceProvider%20%3C-%20configService%20%3C-%20shiurViewLinkFilter
at /home/naftuli/Documents/Work/PyCharm/rtshiurim/bower_components/angular/angular.js:78:12
at /home/naftuli/Documents/Work/PyCharm/rtshiurim/bower_components/angular/angular.js:3479:19
at Object.getService [as get] (/home/naftuli/Documents/Work/PyCharm/rtshiurim/bower_components/angular/angular.js:3606:39)
at /home/naftuli/Documents/Work/PyCharm/rtshiurim/bower_components/angular/angular.js:3484:45
at getService (/home/naftuli/Documents/Work/PyCharm/rtshiurim/bower_components/angular/angular.js:3606:39)
at Object.invoke (/home/naftuli/Documents/Work/PyCharm/rtshiurim/bower_components/angular/angular.js:3628:13)
at /home/naftuli/Documents/Work/PyCharm/rtshiurim/bower_components/angular/angular.js:3485:37
at Object.getService [as get] (/home/naftuli/Documents/Work/PyCharm/rtshiurim/bower_components/angular/angular.js:3606:39)
at /home/naftuli/Documents/Work/PyCharm/rtshiurim/bower_components/angular/angular.js:13687:24
at /home/naftuli/Documents/Work/PyCharm/rtshiurim/test/js/admin/filters/shiur-view-link-test.js:10:22
Error: Declaration Location
at window.inject.angular.mock.inject (/home/naftuli/Documents/Work/PyCharm/rtshiurim/bower_components/angular-mocks/angular-mocks.js:2086:25)
at null.<anonymous> (/home/naftuli/Documents/Work/PyCharm/rtshiurim/test/js/admin/filters/shiur-view-link-test.js:8:9)
TypeError: undefined is not a function
at null.<anonymous> (/home/naftuli/Documents/Work/PyCharm/rtshiurim/test/js/admin/filters/shiur-view-link-test.js:15:16)
How are dependencies handled in Jasmine tests? It seems like it can't find my service, though I'm fairly sure that the service is being imported.
Upvotes: 0
Views: 565
Reputation: 26
Your configService
module should have deAdmin.services.configService
as a module dependency since configService
and shiurViewLink
are in different modules.
angular.module('deAdmin.filters.shiurViewLink', ['deAdmin.services.configService']).filter('shiurViewLink', ['configService', function(configService) {
return function(shiur) {
if (shiur == null)
return "#";
return configService.getAppRoot() + "/shiurim/" + shiur.id + "/";
}
}]);
Upvotes: 1