1
我在生成的項目(由yoeman)面臨一些麻煩並且正在測試。無法在業力單元測試中實例化角度控制器
我想要的是構建一個完全自動化的測試環境。我使用Gulp,Karma,Jasmine和角嘲諷。
TypeError: undefined is not an object (evaluating 'controller.awesomeThings')
在我的控制檯'gulp test'之後它會拋出這個錯誤信息。但這對我來說沒有任何意義。
看看我的測試規範:
'use strict';
describe('Controller: AboutCtrl', function() {
// load the controller's module
beforeEach(function() {
module('evoriApp');
});
var controller;
var scope;
// Initialize the controller and a mock scope
beforeEach(inject(function($controller, $rootScope) {
scope = $rootScope.$new();
controller = $controller('AboutCtrl', {
'$scope': scope
});
}));
it('should attach a list of awesomeThings to the scope', function() {
console.log(controller);
expect(controller.awesomeThings.length).toBe(3);
});
});
和因果報應應該有它需要的任何文件(karma.conf.js):
files: [
// bower:js
'bower_components/angular/angular.js',
'bower_components/angular-animate/angular-animate.js',
'bower_components/angular-aria/angular-aria.js',
'bower_components/angular-cookies/angular-cookies.js',
'bower_components/angular-messages/angular-messages.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-route/angular-route.js',
'bower_components/angular-sanitize/angular-sanitize.js',
'bower_components/angular-material/angular-material.js',
// endbower
'app/scripts/**/*.js',
'test/mock/**/*.js',
'test/spec/**/*.js'
],
這是產生一飲而盡方法的樣子:
gulp.task('test', ['start:server:test'], function() {
var testToFiles = paths.testRequire.concat(paths.scripts, paths.mocks, paths.test);
return gulp.src(testToFiles)
.pipe($.karma({
configFile: paths.karma,
action: 'watch'
}));
});
我不知道失敗在哪裏。我檢查了所有路徑並重寫了多次測試文件...但錯誤沒有改變。
有沒有人有想法,錯誤可能是由什麼引起的?