只是从Jamsine和Karma开始测试。我试图遵循官方的AngularJS文档以及其他几篇文章来设置我的配置并开始测试。当我运行 karma start 时,我得到的这个需求没有定义并且angularDragula没有定义错误。我在这里尝试使用AngularJS控制器。这是我的业力配置文件:
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','browserify'],
plugins: ['karma-jasmine','karma-chrome-launcher','karma-browserify'],
// list of files / patterns to load in the browser
files: [
'public/assets/bower_components/angular/angular.min.js',
'node_modules/angular-mocks/angular-mocks.js',
'public/assets/bower_components/angular-dragula/angular-dragula.js',
'public/app/controllers/testController.js',
'public/app/app.js',
'public/app/controllers/testController.spec.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: {
'public/*.js': ['browserify']
},
// 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
})
}
我尝试搜索require错误,发现在浏览器中进行业力测试时需要browserify。我安装了它并将其添加到配置文件(预处理器)中。但仍然无济于事。
这是我的规格:
describe('Controller Test', function(){
beforeEach(module('App'));
var $controller;
beforeEach(inject(function(_$controller_){
$controller = _$controller_;
}));
describe('$scope.testVar', function(){
var $scope, controller;
beforeEach(function(){
$scope = {};
controller = $controller('testController', {$scope : $scope});
it('checks value for testVar', function(){
expect($scope.testVar).toEqual('hey');
})
})
})
})
我仍然收到此错误:
Chrome 70.0.3538 (Linux 0.0.0) ERROR
{
"message": "An error was thrown in afterAll\nUncaught ReferenceError: require is not defined\nUncaught ReferenceError: angularDragula is not defined",
"str": "An error was thrown in afterAll\nUncaught ReferenceError: require is not defined\nUncaught ReferenceError: angularDragula is not defined"
}
Chrome 70.0.3538 (Linux 0.0.0): Executed 0 of 0 ERROR (0.005 secs / 0 secs)
有人可以帮我吗?