4
votes

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
  });
};
2
Do you perhaps have to add 'require' to your list of used framework like frameworks: ['jasmine', 'requirejs']. (npmjs.com/package/@jrossi/karma-requirejs) For a list of available frameworks: npmjs.org/browse/keyword/karma-adaptertimtos

2 Answers

1
votes

You might need to change the config to something like this

frameworks: ['require', 'jasmine'],

0
votes

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