[英]PACT Provider verification : Expected an Array but got a Hash
在消费者一级的测试是:
describe('Listing first level taxonomies', () => {
before(() => {
return provider.addInteraction({
given: 'GET call for first level taxonomies',
uponReceiving: 'Get object for listing first level
taxonomies',
withRequest: {
method: 'GET',
path: '/api/taxonomies/8061159/taxons?deleted=false',
},
willRespondWith: {
status: 200,
headers: { 'Content-Type': 'application/json' },
body: firstChild
}
});
});
const firstChild = eachLike({
'name': like('Geo'),
'taxons': [
eachLike({
'id': like(115590),
'name': like('Africa'),
'hasChildren':like (false)
})
]
});
当我在提供程序级别进行验证时,出现以下错误:预期为数组,但有哈希值({“ name” =>“ Demo分类法”,“ taxons” => [{“ id” => 8145188,“ name” =>“ manojtaxon”,“ childCategoryName” =>“ hello”,“ hasChildren” => true}出现以下完整错误: https : //pastebin.com/XvB17SXY
请帮助我解决问题我认为在提供者级别上数组大小更多,这就是它失败的原因。尽管我已经添加了like和eachLike(但它仍未解决)。
问题是您的匹配器不正确:
应该是这样的:
const firstChild = like({
'name': 'Geo',
'taxons': eachLike({
'id': 115590,
'name': 'Africa',
'hasChildren': false
})
});
请注意[
和]
的删除。
同样,您可以避免在eachLike
使用like
语句,因为默认情况下是隐含的。 如果你需要使用不同的匹配(例如, term
则可以覆盖该行为,但你似乎只是使用like
这里)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.