Luke Flournoy Luke Flournoy - 3 months ago 24
Javascript Question

Can't find variable: _ when using jasmine to test angularjs service

I am testing an angularjs service that uses the lodash library. when I run the tests through karma-jasmine I get an error

ReferenceError: Can't find variable: _

Is there a way to configure karma/jasmine to use lodash?


Since you won't have a HTML file in your tests to load the script for you, you'll need to include the library in your karma config file in the files property. You can read more about it here:

It will look something like this

In karma.conf.js

files: [

Hope that helps!