This is my JSON file:
{
"courses" : [
{
"id": 1,
"name": "John",
"location": "India",
"courses":["java", "selenium"]
}
]
}
When I try to assert the array property, it shows Assertion Error. This is my Testing script:
var jsonData = pm.response.json();
pm.test("Test array properties", () => {
pm.expect(jsonData.courses).to.include("java");
pm.expect(jsonData.courses).to.have.members(["java", "selenium"]);
});
The error report is as follows:
Test array properties | AssertionError: the given combination of arguments (undefined and string) is invalid for this assertion. You can use an array, a map, an object, a set, a string, or a weakset instead of a string
But when I am adding the array directly in place of variable jsonData, this issue is not appearing. Here is the script:
var jsonData = pm.response.json();
pm.test("Test array properties", () => {
pm.expect(["java", "selenium"]).to.include("java");
pm.expect(["java", "selenium"]).to.have.members(["java", "selenium"]);
});
Please let me know how to fix this issue.
Take a look at your JSON file carefully.
jsonData.coursesdo not have the value["java", "selenium"]jsonData.coursesis an array of objects.then
jsonData.courses[0].coursesis igual to["java", "selenium"]