How To Fix Karma Script Error 0

Aco Mitevski
1 min readSep 4, 2014

I am running karma test runner to execute tests for angular.js. It worked fine most of the time until following error started to appear randomly:

Script error. (:0)

often in combination with:

TypeError: ‘null’ is not an object (evaluating ‘currentSpec.$injector’)
at app/bower_components/angular-mocks/angular-mocks.js:1966

After doing some research on the web I only found 2 resources which suggested to simply use PhantomJS. In my case this didn’t help.

So I did some tedious work and disabled every test one by one without any success.

Then I started disabling different blocks of my application and it turned out that the problem was caused by some external javascript libraries which I was loading during a run block in the main app.js file. One of them was loading of google analytics:

https://gist.github.com/amitevski/60067b61ef18bf87dbf6

So as I don’t need those external libraries for my tests the solution was pretty simple for me.

I just moved the run block into a separate file and excluded them in my karma config.

so app.js now looks like this

angular.module('xyModule', []).config(function() {});

and I created a new file externalLibs.js:

https://gist.github.com/amitevski/c0c8ee0ae2902e9d488a

which I could then exclude in my karma.conf.js

exclude: [‘app/scripts/config/externalLibs.js’],

Thats all. Hope it will help someone.

--

--

Aco Mitevski
Aco Mitevski

No responses yet