问题
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
Uncaught ReferenceError: require is not defined at /Applications/MAMP/htdocs/..../node_modules/angular-mocks/ngAnimateMock.js:1
I also found out that there is no ngAnimateMock.js inside angular-mocks folder.
Here is my karma.conf.js file
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
});
};
回答1:
You might need to change the config to something like this
frameworks: ['require', 'jasmine'],
回答2:
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.
instead of this in your includes node_modules/angular-mocks/.js*
try node_modules//angular-mocks/angular-mocks.js
来源:https://stackoverflow.com/questions/30912738/angularjs-jasmine-karma-uncaught-referenceerror-require-is-not-defined