gpt4 book ai didi

javascript - Jasmine 测试返回错误 "Uncaught ReferenceError: require is not defined"

转载 作者:行者123 更新时间:2023-12-02 15:08:50 25 4
gpt4 key购买 nike

首先,我知道这个问题已经被问过很多次了,但似乎有所不同。

这是我的 karma 配置文件:

// 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文件,我有很多其他错误,似乎它无法识别这个属性?

如何修复该错误?

最佳答案

我建议在项目的根目录中安装 karma-requirejs ,或者在项目本地的所有其他 npm 模块中安装。

关于javascript - Jasmine 测试返回错误 "Uncaught ReferenceError: require is not defined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34926155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com