[英]Angular mock can not find my controller, can not run js unit test with Karma and Requirejs under grunt
Here is my sample code in Git Hub: 这是我在Git Hub中的示例代码:
https://github.com/Mellon/KarmaWithRequirejs.git https://github.com/Mellon/KarmaWithRequirejs.git
when run "grunt test", I get this error. 当运行“grunt test”时,我收到此错误。
Error: [ng:areq] Argument 'MyController' is not a function, got undefined
http://errors.angularjs.org/1.3.14/ng/areq?p0=MyController&p1=not%20a%20function%2C%20got%20undefined
at assertArg (/Users/csun/FrontEnd/KarmaWithRequirejs/node_modules/angular/angular.js:1580)
at assertArgFn (/Users/csun/FrontEnd/KarmaWithRequirejs/node_modules/angular/angular.js:1591)
at /Users/csun/FrontEnd/KarmaWithRequirejs/node_modules/angular/angular.js:8431
at /Users/csun/FrontEnd/KarmaWithRequirejs/test/myControllerSpec.js:13
at invoke (/Users/csun/FrontEnd/KarmaWithRequirejs/node_modules/angular/angular.js:4185)
at workFn (/Users/csun/FrontEnd/KarmaWithRequirejs/node_modules/angular-mocks/angular-mocks.js:2364)
undefined
define(['expect'], function () { 'use strict'; describe('MyController', function () { var controllerContructor, scope, controller; before(function () {//change before to beforeEach, it works. module('app'); inject(function ($controller, $rootScope) { controllerContructor = $controller; scope = $rootScope.$new(); controller = controllerContructor('MyController', {$scope: scope}); }); }); it('shoule be loaded.', function () { expect(controller).to.be.an('object'); }); }); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.