0

i have response body as follows:

{
    "data": {
        "id": 2,
        "email": "janet.weaver@reqres.in",
        "first_name": "Janet",
        "last_name": "Weaver",
        "avatar": "https://reqres.in/img/faces/2-image.jpg"
    },
    "support": {
        "url": "https://reqres.in/#support-heading",
        "text": "To keep ReqRes free, contributions towards server costs are appreciated!"
    }
}
so to validate types in the response  body i have written code as


const jsonData= pm.response.json();
pm.test("testing type in the response body", () =>{
    pm.expect(jsonData).to.be.an("object");
    pm.expect(jsonData.data).to.be.an("object");
    pm.expect(jsonData.id).to.be.a("number");
    pm.expect(jsonData.email).to.be.a("string");
    pm.expect(jsonData.first_name).to.be.a("string");
    pm.expect(jsonData.last_name).to.be.a("string")
});

but i'm getting error as : testing type in the response body | AssertionError: expected undefined to be a number testing type in the response body | AssertionError: expected undefined to be a string

Can anyone help me why am i getting the following errors?

VLAZ
  • 26,331
  • 9
  • 49
  • 67
Rahul
  • 1
  • 1
  • `pm.expect(jsonData.id).to.be.a("number");` -> `pm.expect(jsonData.data.id).to.be.a("number");` and the same for the other things that try to access properties from `.data` but don't access those from `.data` – VLAZ Dec 01 '22 at 07:00
  • thank you so much, i tried same for remaining things, no error. – Rahul Dec 01 '22 at 07:26

0 Answers0