我是单元测试的新手并试图掌握事物。我正在尽力遵循本教程:http ://www.yearofmoo.com/2013/01/full-spectrum-testing-with-angularjs-and-testacular.html#testing-filters 。在我的 AngularJS 应用程序中,我有一个需要测试的过滤器。我已经正确设置并运行了 Node、Testacular 和 Jasmine。我要测试的过滤器非常简单:
myApp.filter('bill_ship', function () {
return function (userData) {
var output = "---";
switch (userData) {
case "0":
output = "Billing";
break;
case "1":
output = "Shipping";
break;
}
return output;
}
});
我以为我的测试设置正确,但它始终失败。
describe("Unit Testing: Filters - ", function() {
beforeEach(angular.mock.module('prismApp', ['bill_ship']));
//BillShip Filter
it('should have a bill-ship filter: ', inject(function($filter){
expect($filter('bill_ship')).not.toEqual(null);
}));
});
它失败并显示以下消息:错误:参数“fn”不是函数,从 bill_ship 获取字符串。
那么......我在哪里做错了?