jasmine-jquery icon indicating copy to clipboard operation
jasmine-jquery copied to clipboard

jasmine.addMatchers throws error

Open sajanchandran opened this issue 10 years ago • 7 comments

After upgrading from 2.1.0 to the latest version of jasmine-jquery in my test, and all of my existing tests are failing, with below error

PhantomJS 1.9.7 (Windows 7) app test country list is loaded successfully FAILED TypeError: 'undefined' is not a function (evaluating 'jasmine.addMatchers') at C:/workspace-sts-2.3.2.RELEASE/eu.europa.ema.esubmission.psur.ui/psur-ui/src/test/resources/jasmine/jasmine-jquery-2.1.0.js:717

Any ideas ? any version problem with jquery or jasmine.

sajanchandran avatar Jun 27 '14 09:06 sajanchandran

Hi @sajanchandran, I had the exact same problem and found out that my global karma-jasmine install was used, which was still at 1.5, so didn't have the addMatchers method. I fixed it by installing the 2.0 version of karma-jasmine globally. Don't know if you use karma, but this might help :)

rulkens avatar Jul 01 '14 15:07 rulkens

I'm using jasmine-jquery 2.0.5 with jasmine 2.0.0 running in-browser and I'm consistently getting this.

The reason appears to be that jasmine-jquery is attempting to call addMatchers() on the jasmine object itself, whereas that function actually exists on the Env object - indeed, adding a call to getEnv() makes the problem go away.

cawhitworth avatar Jul 21 '14 14:07 cawhitworth

@cawhitworth can you tell me more about your fix ? i'm stuck with this issue too :(

stuff avatar Jul 24 '14 20:07 stuff

diff --git a/lib/jasmine-jquery.js b/lib/jasmine-jquery.js
index ab569aa..89071b0 100644
--- a/lib/jasmine-jquery.js
+++ b/lib/jasmine-jquery.js
@@ -349,7 +349,7 @@
   }

   beforeEach(function () {
-    jasmine.getEnv().addMatchers({
+    jasmine.addMatchers({
       toHaveClass: function () {
         return {
           compare: function (actual, className) {

I don't know whether to submit this as a pull request as I'm very much a newcomer to this and I don't know if there's something about my setup causing this, or if it's actually a bug, but the above patch fixes it for me.

cawhitworth avatar Jul 25 '14 11:07 cawhitworth

I used older versions and I don't have this error anymore. thank u anyway ;)

stuff avatar Jul 25 '14 12:07 stuff

It also happened to me with grunt-contrib-jasmine and jasmine-jquery. upgrading grunt-contrib-jasmine to "~0.7.0" fixed the issue.

cesarpachon avatar Aug 13 '14 04:08 cesarpachon

I had this, and upgrading karma-jasmine fixed it for me. See https://github.com/velesin/jasmine-jquery/issues/168

mattwynne avatar Oct 01 '14 13:10 mattwynne