如何使用sinon
s .expects('').withArgs()
函数仅验证对象属性的子集,并完全忽略所有其他属性而不使用sinon.match.any
逐一排除它们?
例如。 myObject
有大约20处房产,我只想期待myObject.name
等于Alex
。
myClass.expects('update')
.withArgs({
name: sinon.match('Alex')
// what else to use here?
})
.yields(null, 'RESULT')
使用sinon.match(object)
,它需要的值“不是null
或undefined
,并且至少具有与预期相同的属性”:
myClass.expects('update')
.withArgs(sinon.match({
name: 'Alex'
}))
.yields(null, 'RESULT')
你试过你的房产是空的报价吗?