我刚刚安装了 Yeoman 并创建了我的第一个项目。我正在尝试对 Yo 创建的默认 Angular 项目进行单元测试。当我调用“grunt server”时,项目运行良好,但是当我运行单元测试“grunt test:unit”时,我收到错误“Argument 'MainCtrl' 不是函数,未定义”。
为了让这个测试正常运行,我缺少什么?
再次感谢
- 控制器
'use strict';
angular.module('myApp')
.controller('MainCtrl', function ($scope) {
$scope.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma',
'mytest'
];
});
-- 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);
});
});