【发布时间】:2016-01-21 14:14:49
【问题描述】:
首先,我知道这个问题已经有人问过,但似乎有所不同。
这是我的业力配置文件:
// Karma configuration
// Generated on Thu Jan 21 2016 09:58:23 GMT-0300 (Argentina Standard Time)
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: [
'src/*.js',
'test/*.js',
'src/*.js',
'tests/*.js'
],
// list of files 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
})
}
这是我到目前为止的测试,以使其正常工作:
require('../src/person.js');
describe('Person ', function(){
it('Should say hi with proposed first name and last name', function() {
var person = new person();
expect(true).toEqual(true);
});
});
当我运行 karma 时,我收到错误消息 require is not defined。
然而,karma-requirejs 是由npm 全局安装的。
我正在阅读这个似乎是同一个问题的问题: Jasmine Tests give error "Uncaught ReferenceError: require is not defined"
但添加后
plugins : [
'karma-requirejs',
],
到 karma conf 文件,我有很多其他错误,似乎它无法识别此属性?
我该如何解决这个错误?
【问题讨论】:
-
你是否安装了所有的 npm 包?我只是好奇,因为我不知道这是否可行。我建议将
karma-requirejs安装在项目的根目录中,或者所有其他 npm 模块都位于项目本地的位置。 -
它可以工作了,现在它正在安装在项目根目录中,那只是测试!谢谢!
标签: javascript jasmine karma-runner