I want to write a test to validate the number of objects nested in "children" is equal to what I am expecting. Let's say in this case it is 2.
This is the response body I am testing against:
{
"result": {
"line_item": {
"name": null,
"description": "abc",
"quantity": 1.0,
"children": [
{
"sku": "xxx",
"quantity": 1.0,
"description": "abc"
},
{
"sku": "yyy",
"quantity": 3.0,
"description": "def"
}
]
}
}
}
I have tried a few things, one of them being this:
let josnData = pm.response.json();
var children = jsonData.result.line_item.chilren;
var length_children = children.length;
pm.test("Only 2 objects in Children", function (){
pm.expect(length_children).to.eql(2);
});
This just throws an error. Would appreciate any ideas how to tackle this. Very new to testing in postman and eager to learn. Thanks!