Luke Flournoy Luke Flournoy - 1 year ago 96
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?

Answer Source

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!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download