Configuring jasmine-jquery to work with Karma
Asked Answered
G

1

7

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?

Gulp answered 15/8, 2014 at 13:7 Comment(0)
S
5

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.

Steffen answered 19/8, 2014 at 17:33 Comment(1)
Hi Tarek, thanks very much for the answer! It finally worked!Gulp

© 2022 - 2024 — McMap. All rights reserved.