运行测试用例时出现此错误:
Error: [ng:areq] Argument 'testcont' is not a function, got undefined
这是我的 ControllerSpec.js
describe('controllers', function(){
var scope;
beforeEach(angular.module('myapp.test'));
beforeEach(inject(function($controller, $rootScope){
scope = $rootScope.$new();
$controller('testcont', {$scope:scope});
}));
it('should', function(){
expect(scope.a).toBe(10)
})
});
这是我的 controllers.js
angular.module('myapp.test', [], function () {
}).controller('testcont', function($scope) {
$scope.a = 10;
});
日志内容
DEBUG [plugin]: Loading plugin karma-junit-reporter.
DEBUG [plugin]: Loading plugin karma-chrome-launcher.
DEBUG [plugin]: Loading plugin karma-firefox-launcher.
DEBUG [plugin]: Loading plugin karma-jasmine.
DEBUG [plugin]: Loading inlined plugin (defining ).
INFO [karma]: Karma v0.10.2 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
DEBUG [launcher]: Creating temp dir at C:\Users\RAJSUB~1\AppData\Local\Temp\karma-48416683
DEBUG [launcher]: C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --user-data-dir=C:\Users\RAJSUB~1\AppData\Local\Temp\karma-48416683 --no-default-browser-check --no-first-run --disable-default-apps --start-maximized http://localh
DEBUG [watcher]: Resolved files:
C:/inetpub/wwwroot/seed/node_modules/karma-jasmine/lib/jasmine.js
C:/inetpub/wwwroot/seed/node_modules/karma-jasmine/lib/adapter.js
C:/inetpub/wwwroot/seed/app/lib/angular/angular.js
C:/inetpub/wwwroot/seed/test/lib/angular/angular-mocks.js
C:/inetpub/wwwroot/seed/app/js/app.js
C:/inetpub/wwwroot/seed/app/js/controllers.js
C:/inetpub/wwwroot/seed/app/js/directives.js
C:/inetpub/wwwroot/seed/app/js/filters.js
C:/inetpub/wwwroot/seed/app/js/services.js
C:/inetpub/wwwroot/seed/test/unit/controllersSpec.js
C:/inetpub/wwwroot/seed/test/unit/directivesSpec.js
C:/inetpub/wwwroot/seed/test/unit/filtersSpec.js
C:/inetpub/wwwroot/seed/test/unit/servicesSpec.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/test/lib/angular/angular-scenario.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/config/karma.conf.js
DEBUG [watcher]: Watching "C:/inetpub/wwwroot/seed/app/lib/angular/angular.js"
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/test/lib/angular/angular-scenario.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/config/karma.conf.js
DEBUG [watcher]: Watching "C:/inetpub/wwwroot/seed/test/lib/angular/angular-mocks.js"
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/test/lib/angular/angular-scenario.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/config/karma.conf.js
DEBUG [watcher]: Watching "C:/inetpub/wwwroot/seed/app/js"
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/test/lib/angular/angular-scenario.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/config/karma.conf.js
DEBUG [watcher]: Watching "C:/inetpub/wwwroot/seed/test/unit"
DEBUG [watcher]: Add file "C:/inetpub/wwwroot/seed/app/lib/angular/angular.js" ignored. Already in the list.
DEBUG [watcher]: Add file "C:/inetpub/wwwroot/seed/test/lib/angular/angular-mocks.js" ignored. Already in the list.
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/test/lib/angular/angular-scenario.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/config/karma.conf.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/test/lib/angular/angular-scenario.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/config/karma.conf.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/test/lib/angular/angular-scenario.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/config/karma.conf.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/test/lib/angular/angular-scenario.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/config/karma.conf.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/test/lib/angular/angular-scenario.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/config/karma.conf.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/test/lib/angular/angular-scenario.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/config/karma.conf.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/test/lib/angular/angular-scenario.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/config/karma.conf.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/test/lib/angular/angular-scenario.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/config/karma.conf.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/test/lib/angular/angular-scenario.js
DEBUG [watcher]: Excluding C:/inetpub/wwwroot/seed/config/karma.conf.js
DEBUG [watcher]: Add file "C:/inetpub/wwwroot/seed/app/js/filters.js" ignored. Already in the list.
DEBUG [watcher]: Add file "C:/inetpub/wwwroot/seed/app/js/controllers.js" ignored. Already in the list.
DEBUG [watcher]: Add file "C:/inetpub/wwwroot/seed/app/js/app.js" ignored. Already in the list.
DEBUG [watcher]: Add file "C:/inetpub/wwwroot/seed/app/js/services.js" ignored. Already in the list.
DEBUG [watcher]: Add file "C:/inetpub/wwwroot/seed/test/unit/directivesSpec.js" ignored. Already in the list.
DEBUG [watcher]: Add file "C:/inetpub/wwwroot/seed/test/unit/filtersSpec.js" ignored. Already in the list.
DEBUG [watcher]: Add file "C:/inetpub/wwwroot/seed/app/js/directives.js" ignored. Already in the list.
DEBUG [watcher]: Add file "C:/inetpub/wwwroot/seed/test/unit/controllersSpec.js" ignored. Already in the list.
DEBUG [watcher]: Add file "C:/inetpub/wwwroot/seed/test/unit/servicesSpec.js" ignored. Already in the list.
DEBUG [web-server]: serving: C:\inetpub\wwwroot\seed\node_modules\karma\static/client.html
DEBUG [web-server]: serving: C:\inetpub\wwwroot\seed\node_modules\karma\static/karma.js
DEBUG [karma]: A browser has connected on socket Uj4-OIYPhAr0oyLxH6vm
INFO [Chrome 30.0.1599 (Windows 7)]: Connected on socket Uj4-OIYPhAr0oyLxH6vm
DEBUG [karma]: All browsers are ready, executing
DEBUG [web-server]: serving: C:\inetpub\wwwroot\seed\node_modules\karma\static/context.html
DEBUG [web-server]: serving: C:/inetpub/wwwroot/seed/node_modules/karma-jasmine/lib/jasmine.js
DEBUG [web-server]: serving: C:/inetpub/wwwroot/seed/node_modules/karma-jasmine/lib/adapter.js
DEBUG [web-server]: serving: C:/inetpub/wwwroot/seed/test/lib/angular/angular-mocks.js
DEBUG [web-server]: serving: C:/inetpub/wwwroot/seed/app/js/app.js
DEBUG [web-server]: serving: C:/inetpub/wwwroot/seed/app/js/controllers.js
DEBUG [web-server]: serving: C:/inetpub/wwwroot/seed/app/lib/angular/angular.js
DEBUG [web-server]: serving: C:/inetpub/wwwroot/seed/test/unit/controllersSpec.js
DEBUG [web-server]: serving: C:/inetpub/wwwroot/seed/app/js/filters.js
DEBUG [web-server]: serving: C:/inetpub/wwwroot/seed/app/js/directives.js
DEBUG [web-server]: serving: C:/inetpub/wwwroot/seed/test/unit/filtersSpec.js
DEBUG [web-server]: serving: C:/inetpub/wwwroot/seed/app/js/services.js
DEBUG [web-server]: serving: C:/inetpub/wwwroot/seed/test/unit/directivesSpec.js
DEBUG [web-server]: serving: C:/inetpub/wwwroot/seed/test/unit/servicesSpec.js
Chrome 30.0.1599 (Windows 7) controllers should FAILED
Error: [ng:areq] Argument 'testcont' is not a function, got undefined
http://errors.angularjs.org/1.2.0-rc.3/ng/areq?p0=testcont&p1=not%20a%20function%2C%20got%20undefined
at C:/inetpub/wwwroot/seed/app/lib/angular/angular.js:78:12
at assertArg (C:/inetpub/wwwroot/seed/app/lib/angular/angular.js:1246:11)
at assertArgFn (C:/inetpub/wwwroot/seed/app/lib/angular/angular.js:1256:3)
at C:/inetpub/wwwroot/seed/app/lib/angular/angular.js:5899:9
at null.<anonymous> (C:/inetpub/wwwroot/seed/test/unit/controllersSpec.js:14:5)
at Object.invoke (C:/inetpub/wwwroot/seed/app/lib/angular/angular.js:3374:28)
at workFn (C:/inetpub/wwwroot/seed/test/lib/angular/angular-mocks.js:2082:20)
Error: Declaration Location
at window.inject.angular.mock.inject (C:/inetpub/wwwroot/seed/test/lib/angular/angular-mocks.js:2068:25)
at null.<anonymous> (C:/inetpub/wwwroot/seed/test/unit/controllersSpec.js:12:16)
at C:/inetpub/wwwroot/seed/test/unit/controllersSpec.js:5:1
Chrome 30.0.1599 (Windows 7): Executed 1 of 1 (1 FAILED) ERROR (0.26 secs / 0.028 secs)