Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring jasmine-jquery to work with Karma

I am trying to configure Karma to use jasmine-jquery without success ...

In my karma.conf.js file I have configured the framework:

frameworks: ['jasmine'],

and have loaded the required dependencies:

    files: [
        '../bower_components/jquery/dist/jquery.js',
        '../bower_components/jasmine-jquery/lib/jasmine-jquery.js',
        ...

But when I run my test using grunt test, I have the following:

    TypeError: undefined is not a function
        at null.<anonymous> (/home/sofarell/workspace/myapp/bower_components/jasmine-jquery/lib/jasmine-jquery.js:352:13)

Looking at the source code of jasmine-jquery.js, it looks like it's not finding the jasmine reference probably because jasmine-jquery is being loaded before jasmine:

351. beforeEach(function () {
352.   jasmine.addMatchers({
353.     toHaveClass: function () {

Anyone else has faced this problem? Is there a way to solve that?

like image 1000
Jefferson Sofarelli Avatar asked Aug 15 '14 13:08

Jefferson Sofarelli


1 Answers

I just worked through this myself, turns out my karma-jasmine version was too old (~0.1.5). Bumped it to ~0.2.0 in packages.json, did an npm install, which installed 0.2.2, and it worked. This github issue from the jasmine-jquery repo was the key.

like image 54
Tarek Avatar answered Nov 19 '22 08:11

Tarek