custom matcher makes jasmine to hang

…衆ロ難τιáo~ 提交于 2019-12-11 23:25:00

问题


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:


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



来源:https://stackoverflow.com/questions/20855087/custom-matcher-makes-jasmine-to-hang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!