jasmine-jquery
jasmine-jquery copied to clipboard
jasmine.addMatchers throws error
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.
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 :)
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 can you tell me more about your fix ? i'm stuck with this issue too :(
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.
I used older versions and I don't have this error anymore. thank u anyway ;)
It also happened to me with grunt-contrib-jasmine and jasmine-jquery. upgrading grunt-contrib-jasmine to "~0.7.0" fixed the issue.
I had this, and upgrading karma-jasmine fixed it for me. See https://github.com/velesin/jasmine-jquery/issues/168