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 configured the framework:

frameworks: ['jasmine'], 

and downloaded the necessary dependencies:

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

But when I run my test using the 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 doesn't seem to find a link to jasmine, probably because jasmine-jquery loads before jasmine:

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

Has anyone else encountered this problem? Is there any way to solve this?

+6
source share
1 answer

I just did it myself, it turns out that my karma-jasmine version was too old ( ~0.1.5 ). I pulled it out at ~0.2.0 in packages.json, did npm install , which installed 0.2.2 , and it worked. This github issue from jasmine-jQuery repo was key.

+5
source

Source: https://habr.com/ru/post/973865/


All Articles