Karma not recognizing jQuery

1k Views Asked by At

I'm using Jasmine testing with Phantomjs and Karma.

I'm getting an error as soon as karma reaches jquery in my included script.

I have it included in my files: [] section however.

Here's what my karma.config.js file looks like

// Karma configuration

module.exports = function(config) {
  config.set({

    basePath: '',


    frameworks: ['jasmine-jquery','jasmine'],


    // list of files / patterns to load in the browser
    files: [

       'resources/assets/bower/jquery/dist/jquery.js',
       'resources/assets/bower/jquery-ui/jquery-ui.min.js',

      // I tried loading them in with a CDN also
       //"https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js",
      //"https://code.jquery.com/ui/1.11.2/jquery-ui.js",

      'public/js/vendor.js',
      'spec/mainjsTests/*.js',
      'spec/javascripts/fixtures/*.css',

      // fixtures
  {
    pattern: 'spec/javascripts/fixtures/*.html',
    watched: true,
    included: true,
    served: true
  }
    ],

    exclude: [
    ],

    preprocessors: {
    },

    reporters: ['progress'],

    port: 9876,

    colors: true,

    logLevel: config.LOG_INFO,

    autoWatch: true,

    browsers: ['PhantomJS'],

    plugins: [
              'karma-*'
             ],

    singleRun: false
  });
};

All my JS files get built into the vendor file so I just linked that one. They're listed in the order they're called from my Gulp file.

As soon as Karma reaches the first line of jQuery it errors out.

$ karma start karma.conf.js
INFO [karma]: Karma v0.12.36 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.8 (Mac OS X 0.0.0)]: Connected on socket sHWba0Xi_dR9PuTbDdhx with id 19415635
PhantomJS 1.9.8 (Mac OS X 0.0.0) ERROR
  TypeError: 'null' is not an object (evaluating 'document.getElementById('uploadFile').files')
  at /Users/me/PersonalProjects/HSAnnotator/public/js/vendor.js:2975

I tested this by commenting out this line, and it then errors out at the next line of jQuery.

Everything besides jQuery is installed with npm, only jquery is installed with bower. I don't think this should matter since I also tried with a CDN link which leads me to believe I have something else in my karma.config file listed wrong.

0

There are 0 best solutions below