两个控制器测试套件,一个给出“错误:[ng:areq] Argument'modalController'不是一个函数,未定义”

时间:2016-03-15 16:33:17

标签: javascript angularjs unit-testing karma-jasmine

控制器测试套件一(主控制器):

describe("RTL cache viewing utility main controller test suite", function () {

var $rootScope, mainCtrl;


beforeEach(module('app'));
beforeEach(inject(function ($controller, $rootScope, $compile, $q) {
    mainScope = $rootScope.$new();
    ctrl = $controller('mainCtrl', {
        $scope: mainScope
    });
}));

然后是另一个描述和it。这个工作正常。

第二个测试套件,适用于我的模态控制器:

describe("RTL cache viewing utility modal controller test suite", function () {

var $rootScope, modalController;

beforeEach(module('app'));
beforeEach(inject(function ($controller, $rootScope, $compile) {
    mainScope = $rootScope.$new();
    ctrl = $controller('modalController', {
        $scope: mainScope
    });

}));

接着是另一个描述和一个it

第二个控制器抛出此错误:Error: [ng:areq] Argument 'modalController' is not a function, got undefined

主控制器的声明:

var app = angular.module("app", ["agGrid", "ui.bootstrap"]);
angular.module("app").controller("mainCtrl", ["$scope", "$timeout", "dateFilter", "$http", "shareDataService", "getDataService", "$q", function ($scope, $timeout, dateFilter, $http, shareDataService, getDataService, $q) {

//stuff
}]);

模态控制器:

angular.module("app").controller("modalCtrl", ["$scope",     "shareDataService", "getDataService", function ($scope, shareDataService,     ngDialog, getDataService) {
//stuff
}]);

1 个答案:

答案 0 :(得分:2)

你似乎混淆了名字

您尝试在测试中使用的控制器被声明为modalCtrl而不是modalController