0
votes

Getting module is not defined when trying to run angularJS unit tests.

I've narrowed down the problem to following issue: Karma is loading angular-mocks.js before it's loading Jasmine, but angular-mocks.js expects Jasmine to be there first.

How can I reorder my Karma file loads to ensure that Jasmine is loaded first?

Here's my karma config:

basePath = '../../../target';
frameworks = ['jasmine'];
files = [
    JASMINE,
    JASMINE_ADAPTER,
    'lib/angular.min.js',
    'lib/angular-mocks.js',
    'main/js/**/*.js',
    'test/js/**/*.js',
];

Versions:

  • angular (and angular mocks) - 1.0.6
  • karma - 0.8.5
1
Have you tried using ANGULAR_SCENARIO and ANGULAR_SCENARIO_ADAPTER? In my karma.conf.js I load them in this order: ANGULAR_SCENARIO, ANGULAR_SCENARIO_ADAPTER, 'http://code.angularjs.org/1.0.6/angular-mocks.js', 'test/scenarios/*.js'. - the-lay
I haven't, but understanding is that the SCENARIO dependencies are for end-to-end tests only (?). I'm currently just unit testing. - Roy Truelove

1 Answers

0
votes

This was due to a typo in my Karma config. Apparently this is what happens..