我想使用karma
和jasmine
运行测试用例。我已经完成了以下操作,但它给出的错误如下:
错误:
Chrome 59.0.3071 (Linux 0.0.0): Executed 0 of 0 ERROR (0.12 secs / 0 secs)
karma.conf.js:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine','requirejs'],
files: [
{pattern: 'node_modules/**/*.js', included: false},
//source files
{pattern: 'src/**/*.js', included: false},
//test files
{pattern: 'tests/**/apptest-spec.js', included: false},
'tests/test-main.js'
],
exclude: [
],
plugins: [
'karma-requirejs',
'karma-chrome-launcher',
'karma-jasmine'
],
preprocessors: {
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
concurrency: Infinity
})
}
apptest-spec.js:
describe('MainCtrl', function() {
beforeEach(module('app-module'));
var $controller;
beforeEach(inject(function(_$controller_){
$controller = _$controller_;
}));
describe('$scope.titleofapp', function() {
var $scope, controller;
beforeEach(function() {
$scope = {};
controller = $controller('MainCtrl', { $scope: $scope });
});
it('sets the title of app to "TestApp" module', function() {
$scope.titleofapp();
expect($scope.title).toEqual('TestApp');
});
});
});
MainCtrl.js:
define(['angular', './app-module'], function(angular, appModule) {
'use strict';
return appModule.controller('MainCtrl', ['$http', '$q', 'appService', '$stateParams', function($http, $q, $stateParams, appService){
$scope.titleofapp = function(){
$scope.title = 'TestApp';
}
}]);
});
测试main.js:
var allTestFiles = [];
var TEST_REGEXP = /(-orchestratespec).js/;
Object.keys(window.__karma__.files).forEach(function(file) {
if (TEST_REGEXP.test(file)) {
var normalizedTestModule = file;
console.log('normalized path', normalizedTestModule);// giving: '/base/tests/controllers/apptest-spec.js'
allTestFiles.push(file);
}
});
console.log(allTestFiles);// giving: ['/base/tests/controllers/apptest-spec.js']
require.config({
baseUrl: '/base/tests/scripts',
paths: {
node_modules: '/base/node_modules',
},
deps: allTestFiles,
callback: window.__karma__.start()
});
我不确定我在哪里做错了,请帮我解决这个问题,以便成功运行我的测试用例。提前谢谢!
注意:如果我在浏览器中重新加载应用程序,我可以在“网络”标签中看到,状态已取消,其名称为:http://localhost:9876/base/tests/controllers/apptest-spec.js?55a86414cf2ce1e51f1c9e865bff8594a27e181f