sinon期望只验证属性的子集

问题描述 投票:0回答:2

如何使用sinons .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
2个回答
1
投票

使用sinon.match(object),它需要的值“不是nullundefined,并且至少具有与预期相同的属性”:

myClass.expects('update')
.withArgs(sinon.match({
  name: 'Alex'
}))
.yields(null, 'RESULT')

0
投票

你试过你的房产是空的报价吗?

© www.soinside.com 2019 - 2024. All rights reserved.