我的单元测试中遇到了karma和jasmine的问题。
看起来它无法识别我的控制器。
我得到了我的karma.conf.js文件,我加载了我的控制器:
// Karma configuration
// Generated on Thu Jun 14 2018 16:51:15 GMT+0200 (Paris, Madrid (heure d’été))
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [ 'Scripts/angular.js','Scripts/angular-mocks.js','main.js','*.js'
],
// list of files / patterns to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
我加载第一个依赖项,然后加载我的控制器(Main.js),然后加载一些实现的服务和测试
这是我宣布我的控制器的方式:
var app = angular.module('App', ['ngMaterial', 'ngMessages'])
app.controller('Ctrl', ['$rootScope', '$scope','$http','$timeout','$mdDialog','Global', 'projects', 'screens', 'users', 'licenses', function($rootScope, $scope, $http, $timeout, $mdDialog,Global, projects, screens, users, licenses) {
...}
这是我的测试文件:
describe('MainController',()=>{
beforeEach(()=>{angular.module('App')});
var controller,scope;
beforeEach(inject((_$rootScope_,$controller)=>{
scope = _$rootScope_.$new();
controller = $controller('Ctrl',{$scope : scope});
}));
it('should be defined',()=>{
expect(controller).toBeDefined();
})
});
实际上,当我尝试运行测试时,我遇到了这个错误:
我很确定我的Main.js文件的路径很好。
这是我使用的树:
root
|---Scripts
|---index.html
|---karma.conf.js
|---main_test.js
|---main.js
|---firstService.js
|---secondService.js
|---....
请问我做错了什么?