Getting this error when run ng test.
TypeError: Cannot read properties of undefined (reading 'id')
this.slotSvc.getFiscalWeek(startDate, 1)
.then(function (data) {
const inductionYear = (data[0].id).split('-')[1];
const shopId = slot.shop.id;
const ohLines = [];
this.slotSvc.getOlLinesForShop(shopId, inductionYear)
.subscribe(function (d) {
_.each(d, function (dataOL) {
let slotLineType;
if (slot.linetype) {
slotLineType = slot.linetype;
} else {
slotLineType = slot.assignedAssetInfo.lineTypes[0];
}
if (dataOL.lineTypes[0] === slotLineType && dataOL.name.includes(slot.assetType)) {
const olJson = { 'id': dataOL.id, 'displayName': dataOL.displayName };
ohLines.push(olJson);
}
}.bind(this));
Seems like you are accessing id props from data that does not exists. Try to monitor data params and log data if it contains id prop or not.
you can do like this const inductionYear = (data[0]?.id).split('-')[1];
after putting question mark it will not give any undefined error.