I am verifying if my values match with JSON response. Here is my code -
pm.test("Status test", function () {
pm.response.to.have.status(200);
});
pm.test("Testing Related Products", function () {
let responseJSON = pm.response.json();
if (responseJSON.contains.length > 0) {
let expectedStrings = pm.variables.get("related_prod_ids").split(",");
console.log("Expected String -",expectedStrings); //["111537", "111345"]
let actualString = responseJSON.contains[0].relatedProducts.map(product => product.productCode.toString());
console.log("Actual String -", actualString);//["111537"]
if (pm.expect(actualString).to.have.members(expectedStrings)) {
console.log("Testcase Passed!");
} else {
console.log("One or more Related Products did not match...!");
}
} else {
console.log("Empty response...");
}
});
Query - I get an error - Testing Related Products | AssertionError: expected [ â111537â ] to have the same members as [ â111537â, â111345â ]
But Console never shows - console.log(âOne or more Related Products did not matchâŚ!â);
What am I doing wrong?