【发布时间】:2015-12-21 19:14:00
【问题描述】:
我正在尝试为我的 AngularJS 应用程序进行一些单元测试。我已经制作了几个测试套件,它们都可以工作。但是,在测试某个controller 时,出现以下错误:
Error: [ng:areq] Argument 'fn' is not a function, got string
它的起源似乎在于注入依赖项。这是beforeEach 代码:
beforeEach(function () {
angular.mock.module('mapInteractions');
inject(function(_$controller_, _$rootScope_, _$q_) {
$controller = _$controller_;
$rootScope = _$rootScope_;
$q = _$q_;
}); //<-------- IT BLAMES THIS EXPRESSION
inject(function(_userProgressService_,
_mapMarkersService_,
_PointAPlaceController_) {
//custom services and controllers
userProgressService = _userProgressService_;
mapMarkersService = _mapMarkersService_;
PointAPlaceController = _PointAPlaceController_;
}); //if I remove the previous inject, it blames this one
//...
}
我最初使用BardJS's inject method,因为它可以与其他所有套件一起使用,但后来我尝试了,如您所见,错误仍然存在。
这真的很奇怪,因为我正在以完全相同的方式测试另一个控制器,但一切都很好。
你能发现有什么不对吗?
【问题讨论】: