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)
| 归档时间: |
|
| 查看次数: |
3755 次 |
| 最近记录: |