Test Valadation Errors In Test

Hi , this is Json code for Employees that I have created

{
  "Employees": [
    {
      "id": "1",
      "name": "RAMESH",
      "Location": "India",
      "phoneno": "8223345881",
      "courses": [
        "mechanical",
        "Blast furnance"
      ]
    },
    {
      "id": "2",
      "name": "Hritik",
      "Location": "India",
      "phoneno": "9902115881",
      "courses": [
        "electrical",
        "Electric Departement"
      ]
    },
    {
      "id": "3",
      "name": "Shashi",
      "Location": "India",
      "phoneno": "7789923381",
      "courses": [
        "Diploma-safety deparment",
        "Resource Departement"
      ]
    }
  ]
}

To validating Response Body through test

const jsonData = pm.response.json();
	 pm.test("Test data type of the response", () => { pm.expect(jsonData).to.be.an("object");
	 pm.expect(jsonData.name).to.be.a("string"); 
	 pm.expect(jsonData.id).to.be.a("number");
	 pm.expect(jsonData.courses).to.be.an(array); 
});

I’m getting this error msg in the test window

" AssertionError: expected [ …(3) ] to be an object "

Please help I’m new to this postman n I’m stuck in this

Hey @krutitester :wave:

I’m surprised to see that not fail earlier in the test, as after you have checked that the response is an object - the reference to the next set of keys wouldn’t be correct.

You’d need to map or iterate through the data and then check the types and values of those keys.

What are you trying to test here? What’s the overall use case?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.