我对AngularJS控制器的Karma和Jasmine测试有问题。我在StackOverflow上阅读了很多关于这个主题的内容,我确信加载文件顺序没问题,但是我一直得到错误:
TypeError: module is not a function at Suite.<anonymous> (/app/karma/developers/developer.ut.js:6:16) at /app/karma/developers/developer.ut.js:1:1
我的karma.config.js:
module.exports = function(config) {
config.set({
basePath: './app',
files: [
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/angular-route/angular-route.js',
'app.js',
'developers/*.js',
'karma/developers/*.js',
'karma/*.js'
],
autoWatch: true,
frameworks: ['jasmine'],
browsers: ['Chrome'],
plugins: [
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-jasmine',
'karma-junit-reporter'
],
junitReporter: {
outputFile: 'test_out/unit.xml',
suite: 'unit'
}
});
};
我的developer.ut.js:
describe('DeveloperCtrl', function () {
var $rootScope;
var $controller;
var YourControllerHere;
beforeEach(module('myApp.developers'));
beforeEach(inject(function($injector) {
$rootScope = $injector.get('$rootScope');
$controller = $injector.get('$controller');
$scope = $rootScope.$new();
}));
beforeEach(inject(function($controller) {
YourControllerHere = $controller("DeveloperCtrl");
}));
it('jak działa', function () {
expect(YourControllerHere.message).toBe("Hello");
});
});