Search code examples
javascriptpostmanpostman-testcase

How do I asset an object inside an array


new to postman and JavaScript. I am trying to asset the "message" and ""Some Message." in below postman test script but keep getting an error Please advice where am I going wrong.

[
{
    "documentId": "123",
    "documentName": "AB.pdf",
    "status": "Failed",
    "errors": [
        {
            "category": "Invalid",
            "message": "Some Message."
        }
    ]
}
]




**My Script:**
const jsonData = pm.response.json();
pm.test("Error message", () => {
const errormessgae = jsonData.errors.find;
(m => m.message === "Some Message.");
})

Test response Error I receive is " Error message | TypeError: Cannot read property 'find' of undefined"


Solution

  • i am not sure why you are using find method

    pm.expect(pm.response.json()[0].errors[0].message).to.eq("Some Message")