【发布时间】:2012-02-15 09:28:42
【问题描述】:
我在一些 Jasmine 测试规范中有一个自定义匹配器:
this.addMatchers({
checkContains: function(elem){
var found = false;
$.each( this.actual, function( actualItem ){
// Check if these objects contain the same properties.
found = found || actualItem.thing == elem;
});
return found;
}
});
当然,actualItem.thing == elem 实际上并不比较对象内容——我必须使用Object comparison in JavaScript 中更复杂的解决方案之一。
我不禁注意到,Jasmine 已经有了一个很好的对象相等检查器:expect(x).toEqual(y)。有没有办法在自定义匹配器中使用它?有没有什么通用的方法可以在自定义匹配器中使用匹配器?
【问题讨论】:
标签: javascript unit-testing jasmine matcher