Arfat
Arfat

Reputation: 127

"ReferenceError: Can't find variable: $j.." while testing in jasmine

I am new to jasmine test cases. I was trying to write a test case for one of the scenarios where we are using $j.map() function ($j as in jquery) in our controller. When the test is executed the spec fails with the following error:

ReferenceError: Can't find variable: $j in xyzController.js.

I changed it to JavaScript array.map() and the test case passed with no error.

The problem is I need to use jQuery map since array.map does not work in IE8 and jQuery map does. Though I can use shim/polyfill provided by MDN, but I'm hoping we can make it work without adding anything extra.

Is there a workaround for this problem?

Upvotes: 0

Views: 747

Answers (1)

Arfat
Arfat

Reputation: 127

Ok, so after a lot of troubleshooting and going through forums and searching net, i found a solution. I had to install karma-jasmine-jquery-2 (not karma-jasmine-jquery, as that gave error that it could not connect to github, when installing via NPM), as discussed on this forum: https://github.com/bessdsv/karma-jasmine-jquery/issues/8#issuecomment-215121620

Then followed karma-jasmine-jquery's usage from here: https://www.npmjs.com/package/karma-jasmine-jquery#usage

and that solved my $j dependency issue.

Upvotes: 1

Related Questions