【发布时间】:2015-04-27 06:53:48
【问题描述】:
我对 AngularJS 中的测试完全陌生。我已经设置了业力,现在正在尝试在我编写的工厂中测试某个功能。
这是我工厂的一个sn-p:
app.factory('helpersFactory', ['constants', function (constants) {
return {
someFunction: function() {
},
is24x24Icon: function (iconNum) {
return ((iconNum >= 10090 && iconNum <= 10125) ;
}
};
}]);
然后我有这个测试:
describe('Factory: helpersFactory', function () {
beforeEach(module('ppMobi'));
var fct;
beforeEach(inject(function ($factory) {
fct = $factory('helpersFactory');
}));
it('should detect iconNum 10090 is a 24 x 24 icon', function () {
var iconNum = 10090;
var is24x24Icon = fct.is24x24Icon(iconNum);
expect(is24x24Icon).toBeTruthy();
});
});
我从 Karma 收到一条错误消息,告诉我它无法读取未定义的“is24x24icon”。因此我只能假设我的工厂在测试期间没有正确创建。我确实依赖于其他函数使用的工厂中的常量。这只是我在主应用程序模块上设置的 angular.constant()。
我找到了一些其他帖子,但不确定如何继续,我需要将我的常量依赖项注入到我的测试中吗?
【问题讨论】: