sinon 期望只验证属性的子集
sinon expects validate only subset of properties
如何使用 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')
您是否在 属性 为 null 的位置尝试了引号?
使用 sinon.match(object)
需要值 "to be not null
or undefined
and have at least the same properties" 作为期望:
myClass.expects('update')
.withArgs(sinon.match({
name: 'Alex'
}))
.yields(null, 'RESULT')
如何使用 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')
您是否在 属性 为 null 的位置尝试了引号?
使用 sinon.match(object)
需要值 "to be not null
or undefined
and have at least the same properties" 作为期望:
myClass.expects('update')
.withArgs(sinon.match({
name: 'Alex'
}))
.yields(null, 'RESULT')