I'm trying to test a angular app using Jasmine-Karma. I'm total newbie in the "testing/console/npm" field, so I'd like to ask you for an easy explanation (and some fix as well) what is causing the error
我正在尝试使用Jasmine-Karma测试一个角度应用程序。我在“testing / console / npm”字段中总是新手,所以我想问你一个简单的解释(以及一些修复)导致错误的原因
Uncaught ReferenceError: require is not defined at /Applications/MAMP/htdocs/..../node_modules/angular-mocks/ngAnimateMock.js:1
未捕获的ReferenceError:在/Applications/MAMP/htdocs/..../node_modules/angular-mocks/ngAnimateMock.js:1中未定义require
I also found out that there is no ngAnimateMock.js inside angular-mocks folder.
我还发现angular-mocks文件夹中没有ngAnimateMock.js。
Here is my karma.conf.js file
这是我的karma.conf.js文件
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
'public/vendor/angular/angular.js',
'node_modules/angular-mocks/*.js',
'public/vendor/traceur/bin/traceur.js',
'public/js/*.js',
'test/spec/spec.js',
],
exclude: [
],
preprocessors: {
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
2 个解决方案
#1
1
You might need to change the config to something like this
您可能需要将配置更改为此类似的内容
frameworks: ['require', 'jasmine'],
框架:['require','jasmine'],
#2
0
Be careful with * includes in your karma config, for libraries you want to just include the JavaScript file you need, not everything in the directory.
小心你的karma配置中的* includes,对于你想要包含所需JavaScript文件的库,而不是目录中的所有内容。
instead of this in your includes node_modules/angular-mocks/.js*
而不是在你的包含node_modules / angular-mocks / .js *
try node_modules//angular-mocks/angular-mocks.js
尝试node_modules // angular-mocks / angular-mocks.js
#1
1
You might need to change the config to something like this
您可能需要将配置更改为此类似的内容
frameworks: ['require', 'jasmine'],
框架:['require','jasmine'],
#2
0
Be careful with * includes in your karma config, for libraries you want to just include the JavaScript file you need, not everything in the directory.
小心你的karma配置中的* includes,对于你想要包含所需JavaScript文件的库,而不是目录中的所有内容。
instead of this in your includes node_modules/angular-mocks/.js*
而不是在你的包含node_modules / angular-mocks / .js *
try node_modules//angular-mocks/angular-mocks.js
尝试node_modules // angular-mocks / angular-mocks.js