Getting TypeError " Cannot read properties of undefined (reading 'employee_name')"

Hi All,

I am getting the below issue once I run the collection for the multiple set of data (Users.csv).

End Point: dummy.restapiexample.com/api/v1/employees
HTTP Method: GET

Code:

pm.test(ā€œ200 statusā€, function() {
pm.response.to.have.status(200);

});

pm.test(ā€œResponse timeā€, function(){
pm.expect(pm.response.responseTime).to.be.below(4000)

});
const auth = undefined;
console.log(auth?.employee_name); // undefined
console.log(auth?.employee_name?.employee_name);

pm.test(ā€œVerify login userā€, function() {

const response = pm.response.json();

pm.expect(response.json.employee_name).to.eql(pm.iterationData.get("Emp_Name"));
pm.expect(response.json.employee_salary).to.eql(pm.iterationData.get("Emp_Salary"));
pm.expect(response.json.employee_age).to.eql(pm.iterationData.get("Emp_Age"));

});

Error:

Verify login user | TypeError: Cannot read properties of undefined (reading ā€˜employee_nameā€™)

Please assist on resolving this issue.

What is is this doing?

const auth = undefined;
console.log(auth?.employee_name); // undefined
console.log(auth?.employee_name?.employee_name);

This isnā€™t what is causing your problem, but I canā€™t work out what is actually doing.

The problem is with your assertion.

pm.expect(response.employee_name).to.eql(pm.iterationData.get("Emp_Name"));

Youā€™ve already parsed the response. You havenā€™t included an example response but Iā€™m going to guess that it should be response.employee_name.

The error is reporting back as undefined as it canā€™t find the value.

Hi mdjones,

Thank you so much, it got resolved I have updated the assertion which you have provided. It is working now.