Pablo
Pablo

Reputation: 10602

Jasmine Test returns error "Uncaught ReferenceError: require is not defined"

First of all, I know this question has been asked other times, but it seems to be different.

This is my karma config file:

// 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
  })
}

This is my test so far in order to make it work:

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);
    });
});

When I run karma I'm getting the error saying require is not defined. How ever, karma-requirejs is installed globally by npm.

I was reading this question that seems to be the same problem: Jasmine Tests give error "Uncaught ReferenceError: require is not defined"

But after adding

plugins : [
    'karma-requirejs',
],

to the karma conf file, I have a lot of other errors, that seems it does not recognize this attibute?

How can I fix the error?

Upvotes: 0

Views: 2388

Answers (1)

Healforgreen
Healforgreen

Reputation: 579

I suggest installing karma-requirejs in your project's root, or where all of your other npm modules live local to the project.

Upvotes: 2

Related Questions