我有一个带参数的过滤器:
{{'filter input' | filterName:arg1:arg2}}
通常我要测试过滤器:
it('should work',inject(function($filter){
expect($filter('filterName')('filter input')).toEqual('whatever');
}));
如何在测试中包含其他参数:arg1:arg2
?
答案 0 :(得分:2)
实际上有点显而易见:
it('should work',inject(function($filter){
expect($filter('filterName')('filter input', 'arg1', 'arg2)).toEqual('whatever');
}));
答案 1 :(得分:0)
.filter('SomeFilter', function () {
return function (arg1, arg2) {
return arg1 + ' ' + arg2;
}
}
您可以像这样测试:
it('should work', inject(function($filter) {
var arg1 = 'hello';
var arg2 = 'world';
var someFilter = $filter('SomeFilter');
var result = someFilter(arg1, arg2);
expect(result).toBe(arg1 + ' ' + arg2);
}));
还有其他语法内容。我刚刚找到了我提到的关于testing filters in angularjs
的博文