如何为我创建单元测试Angularjs过滤器调用?当前代码给出了错误:
错误:[$ injector:unpr] http://errors.angularjs.org/1.6.0/ $注射器/ unpr?P0 = DateForFrontEndFilterFilterProvider%20%3 C-%20DateForFrontEndFilterFilter at public / scripts / angular / angular.min.js:6:425 at public / scripts / angular / angular.min.js:44:395
我的代码如下:
过滤代码:
app.filter('DateForFrontEndFilter', ['$filter', 'ngOtherSettings', function($filter, ngOtherSettings) {
return function(date) {
var format = ngOtherSettings.FrontEndDateFormat;
var result = $filter('date')(date, format, null);
测试代码:
describe('DateForFrontEndFilter tests', function() {
beforeEach(function() {
module.apply('myApp');
inject(function($injector) {
filter = $injector.get('$filter')('DateForFrontEndFilter');
});
var testDate = "10/12/2017 10:32:12";
});
it('check date from DateForFrontEndFilter for date with format long', function() {
var ngOtherSettings = { FrontEndDateFormat: 'dd/MM/yyyy HH:mm:ss' };
var result = filter(ngOtherSettings, testDate);
expect(result).toBe(testDate + "sda");
});
return result;
};
}]);
...