0

Trying to call this custom matcher in jasmine testing tool but I got this error:

TypeError: matcherCompare is undefined
var result = matcherCompare.apply(null, args);
jasmine.js (line 1192)

My matcher:

/*
 * Extends jasmine expectations by defining new matchers
 */
beforeEach(function () {
   jasmine.addMatchers({
      toEqualArray: function(){
         var s = typeof this.actual,
             result = false; 
         if (s === 'object'){
            if (this.actual){
               if (Object.prototype.toString.call(this.actual) === Object.prototype.toString.call([])) { //'[object Array]'
                  result = true;
               }
            }
         }
         this.message = function(){
            if (result){
               return "Is Array";
            }
            return "Is not an Array";
         };
         return result;
      }
   });
});

The core of the code inside toEqualArray is already tested as a simple js function and is ok. My matcher doesn't have an argument as you can see. I use jasmine 2.0 standalone for my tests and my matcher resides in an external js file like in the example at the standalone version of jasmine. I even moved my matcher inside my specs replacing jasmine with this but with no result! What am I doing wrong?

Jasmine hangs when I put in my spec this specific command:

expect(o.get('any')).toEqualArray();

where o is my object that returns (I tested and it's ok) an array!

I have to debug jasmine now :(

1

1 Answer 1

1

For jasmine 2.0, the syntax for custom matchers was changed. Updated documentation is here: http://jasmine.github.io/2.0/custom_matcher.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.