错误:参数'MainCtrl'不是函数,未定义

use*_*483 5 javascript unit-testing angularjs

我刚刚安装了Yeoman并创建了我的第一个项目.我试图让我的头围测试由Yo创建的默认角度项目.当我调用"grunt服务器"时,项目运行正常,但是当我运行单元测试"grunt test:unit"时,我得到错误"Argument'MainCtrl'不是函数,未定义".

为了让这个测试正常运行,我缺少什么?

再次感谢

- 控制器

'use strict';

angular.module('myApp')
.controller('MainCtrl', function ($scope) {
$scope.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma',
'mytest'
  ];
});
Run Code Online (Sandbox Code Playgroud)

- unti测试

 'use strict';

 describe('Controller: MainCtrl', function () {

 // load the controller's module
 beforeEach(module('myApp'));

var MainCtrl,
 scope;

  // Initialize the controller and a mock scope
 beforeEach(inject(function ($controller, $rootScope) {
  scope = $rootScope.$new();
 MainCtrl = $controller('MainCtrl', {
 $scope: scope
});
}));

it('should attach a list of awesomeThings to the scope', function () {
expect(scope.awesomeThings.length).toBe(4);
});
});
Run Code Online (Sandbox Code Playgroud)

nul*_*ull 3

如果我复制并粘贴此代码,它将毫无问题地执行。您收到的错误消息表明注入器不知道控制器(名称)。您是否忘记将控制器 javascript 文件包含在karma.conf.js中?