postman jetpacks - testing for nested data

依然范特西╮ 提交于 2019-12-04 08:18:16

You can test for nested data much in the same way you test for data that is not nested (using dot notation)

I created a really quick dummy service that returns the the following json:

{
  "one": "1",
  "two": "2",
  "three": {
    "four": "4",
    "five": "5"
  }
}

In the following snippet I test (using dot notation) values in the nested object. In particular I'm asserting that the object three has properties of four and five that are set to the values of "4" and "5" respectively:

var data = JSON.parse(responseBody);
tests["4"] = data.three.four === "4";
tests["5"] = data.three.five === "5";

Here's my setup in postman with the corresponding json response:

Here are my test results:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!