AngularJS - 测试特定控制器时获得 "Argument 'fn' is not a function, got string"

AngularJS - Getting "Argument 'fn' is not a function, got string" when testing a specific controller

我正在尝试为我的 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,因为它与所有其他套件一起工作,但后来我尝试了,如您所见,但错误仍然存​​在。

这真的很奇怪,因为我正在以完全相同的方式测试另一个控制器,但一切正常。

你能发现问题吗?

听起来您的模拟服务或控制器定义返回的是字符串而不是函数。

所以问题可能出在服务定义中,而不是在 inject 语句中 - 它只是在尝试注入无效服务时失败了。

检查是否有任何模拟服务返回字符串作为测试值 - Angular 可能将该服务实例作为提供者调用,然后错误地将字符串视为服务定义。