如何在Angular中对过滤器进行单元测试?
注入$filter然后用$filter('filterName')(input, options);
$filter
$filter('filterName')(input, options);
所以要测试这个模板的等效性 {{ foo | testFilter:capitalize }}
{{ foo | testFilter:capitalize }}
describe('The test filter', function () { 'use strict'; var $filter; beforeEach(function () { module('myTestFilterModule'); inject(function (_$filter_) { $filter = _$filter_; }); }); it('should capitalize a string', function () { // Arrange. var foo = 'hello world', result; // Act. result = $filter('testFilter')(foo, 'capitalize'); // Assert. expect(result).toEqual('HELLO WORLD'); }); });