【发布时间】:2013-12-31 09:33:48
【问题描述】:
尝试在 jasmine 测试工具中调用此自定义匹配器,但出现此错误:
TypeError: matcherCompare is undefined
var result = matcherCompare.apply(null, args);
jasmine.js (line 1192)
我的匹配器:
/*
* 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;
}
});
});
toEqualArray里面的代码核心已经作为一个简单的js函数测试过了,没问题。如您所见,我的匹配器没有参数。我使用 jasmine 2.0 独立版本进行测试,而我的匹配器位于外部 js 文件中,就像在 jasmine 独立版本的示例中一样。我什至在我的规范中移动了我的匹配器,用this 替换了jasmine,但没有结果!
我做错了什么?
当我在我的规范中输入这个特定命令时,Jasmine 挂起:
expect(o.get('any')).toEqualArray();
o 是我的对象,它返回(我测试过,没问题)一个数组!
我现在必须调试 jasmine :(
【问题讨论】:
-
搜索匹配器 我找到了这些链接:1) github.com/velesin/jasmine-jquery, 2) github.com/froots/jasmine-sinon, 3) github.com/searls/jasmine-fixture 和 4) github.com/jeffwatkins/jasmine-dom。任何想法最适合基于 jquery+自定义代码的 js&ajax 测试?
标签: javascript unit-testing testing jasmine