我正在进行一个API调用,该调用将在主体中返回JSON,并且我想将JSON对象与String进行比较。我怎样才能做到这一点?
APIres.body
返回以下JSON对象:
{
"name": "tenant_tree",
"documents": [
{
"tags": [],
"scope": "all",
"tenant_id": "0",
"id": "9dd2c5a5-2de2-4ac8-b195-04290f83b6fb",
"version": 1,
"description": "",
"name": "0",
"grouping": "",
"perm_read": "all",
"perm_write": "all",
"version_author": "dg",
"version_date": 1470324147050,
"is_current": true,
"dependencies_guid": [""],
"dependencies_name": [""],
"display_name": "system"
},
}
我想比较类似的东西,expect(res.body).toMatch('"name": "0"');
但这失败了。
我可以通过以下方式比较API响应正文中的json值:
expect(res.body.name).toEqual("0")
无需解析响应。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句