我正在尝试为我的 Angular.js 应用程序编写单元测试,但我无法注入我需要的东西(它无法找到合适的提供者)。
有人看到我错过了什么吗?
Firefox 21.0 (Linux) filter staticList should convert static list object into its display value FAILED
Error: Unknown provider: staticListProvider <- staticList in /path/to/my-app/public/third-party/angular/angular.js (line 2734)
createInjector/providerInjector<@/path/to/my-app/public/third-party/angular/angular.js:2734
getService@/path/to/my-app/public/third-party/angular/angular.js:2862
createInjector/instanceCache.$injector<@/path/to/my-app/public/third-party/angular/angular.js:2739
getService@/path/to/my-app/public/third-party/angular/angular.js:2862
invoke@/path/to/my-app/public/third-party/angular/angular.js:2880
workFn@/path/to/my-app/test/lib/angular/angular-mocks.js:1778
angular.mock.inject@/path/to/my-app/test/lib/angular/angular-mocks.js:1764
@/path/to/my-app/test/unit/filtersSpec.js:19
@/path/to/my-app/test/unit/filtersSpec.js:16
@/path/to/my-app/test/unit/filtersSpec.js:3
应用程序:
angular.module('myApp', ['myAppFilters', 'ui.bootstrap', '$strap.directives']).
// Some other stuff
过滤器:
"use strict";
angular.module('myAppFilters', []).
filter('staticList', function () {
return function (listItem) {
if (!listItem) {
return '';
}
return listItem.value;
};
});
考试:
'use strict';
describe('filter', function () {
beforeEach(angular.module('myAppFilters'));
describe('staticList', function () {
it('should convert static list object into its display value',
inject(function (staticList) {
expect(undefined).toBe('');
expect({key: 'A', value: 'B'}).toBe('B');
}));
});
});
业力配置:
basePath = '../';
files = [
JASMINE,
JASMINE_ADAPTER,
'public/third-party/jquery/*.js',
'public/third-party/angular/angular.js',
'public/third-party/angular/i18n/angular-*.js',
'public/third-party/moment/moment.min.js',
'public/third-party/moment/moment-*.js',
'public/js/**/*.js',
'test/lib/**/*.js',
'test/unit/**/*.js'
];
colors = true;
autoWatch = true;
browsers = ['Firefox'];
junitReporter = {
outputFile: 'test_out/unit.xml',
suite: 'unit'
};
如果有人想查看完整代码,应用程序存储库在这里:https ://github.com/adericbourg/GestionCourrier
非常感谢,
阿尔班