我在一些形式的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;
}
});
Run Code Online (Sandbox Code Playgroud)
当然,actualItem.thing == elem实际上并没有比较对象内容 - 我必须在JavaScript中使用对象比较中的一个更复杂的解决方案.
不过,我不禁注意到,Jasmine已经有了一个很好的对象相等检查器:expect(x).toEqual(y).有没有办法在自定义匹配器中使用它?有没有在自定义匹配器中使用匹配器的一般方法?