0

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"

AaravB
  • 3
  • 1

1 Answers1

0

i am not sure why you are using find method

pm.expect(pm.response.json()[0].errors[0].message).to.eq("Some Message")
PDHide
  • 18,113
  • 2
  • 31
  • 46
  • Honestly I am very new to postman or JavaScript, I saw the same e.g on postman's site. I tried your recommendation but I got this "TypeError: pm.expect(...).to.be is not a function" – AaravB Aug 04 '21 at 15:14
  • @AaravB sorry updated the answer , postman assertions are chai assertions so to.be is not chai . corrected it : https://www.chaijs.com/api/bdd/ – PDHide Aug 04 '21 at 17:37