Not completely sure without having that in front of me to run but you could use _.get() to check to see if that object is present in the array, if it is…run the test.
if(_.get(response.statusHistory, '[2].statusCode') !== undefined) {
pm.test("Status is BOOKED", () => {
pm.expect(response.statusHistory[2].statusCode).to.eql("BOOKED")
});
}
or you could add something different that runs a ‘skipped’ test unless the object is present
let skipTest = _.get(response.statusHistory, '[2].statusCode') === undefined;
(skipTest ? pm.test.skip : pm.test)("Status is BOOKED", () => {
pm.expect(response.statusHistory[2].statusCode).to.eql("BOOKED")
});