AssertionError: expected undefined to equal

Hi!!! I need Help

i have a GET request which returns:

[
{
“ContractorCompanyName”: null,
“LastName”: “Lopez”,
“SupervisorTechnicianNum”: “AA23DC”,
“SignatureCaptureCapableInd”: “Y”,
“LastLoginDateTime”: “2023-05-29T11:54:07-03:00”,
“PhoneNum”: null,
“AltNum”: null,
“GPSDeviceNum”: “gpsandroid-10106”,
“licenses”: null,
“EmployeeId”: null,
“eCardContactHours”: null,
“TechnicianNum”: “AQ21SAD007”
}
]

I want to add asertion and tried this:

pm.test(“Validar tecnico”, function () {
var jsonData = pm.response.json();
pm.expect(jsonData.TechnicianNum).to.equals(“AQ21SAD007”);
});

But failed, returns this:

AssertionError: expected undefined to equal ‘AQ21SAD007’

Any help please.
Thank you so much!

Your response is an array with a single object in it.

Array indexes start at 0.

Therefore it would be


pm.test("Validar tecnico", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData[0].TechnicianNum).to.equals("AQ21SAD007");
});
1 Like

Excellent, it works!!!
thank you so much