diff --git a/lib/core/src/lib/datatable/components/datatable-cell/datatable-cell.component.spec.ts b/lib/core/src/lib/datatable/components/datatable-cell/datatable-cell.component.spec.ts index 917077853b..74666a60d9 100644 --- a/lib/core/src/lib/datatable/components/datatable-cell/datatable-cell.component.spec.ts +++ b/lib/core/src/lib/datatable/components/datatable-cell/datatable-cell.component.spec.ts @@ -120,4 +120,23 @@ describe('DataTableCellComponent', () => { checkDisplayedText('hello worl...'); checkDisplayedTooltip('hello world'); }); + + it('should compute empty title when column value is undefined', () => { + const row: DataRow = { + id: '1', + isSelected: false, + hasValue: () => false, + getValue: () => undefined, + obj: 'Initial Value', + cache: [] + }; + + component.data = new ObjectDataTableAdapter(); + component.column = { key: 'car_name', type: 'text', maxTextLength: 10 }; + component.row = row; + + expect(() => fixture.detectChanges()).not.toThrow(); + expect(component.computedTitle).toBe(''); + expect(testingUtils.getByCSS('span').nativeElement.title).toBe(''); + }); }); diff --git a/lib/core/src/lib/datatable/components/datatable-cell/datatable-cell.component.ts b/lib/core/src/lib/datatable/components/datatable-cell/datatable-cell.component.ts index 02b76fa6c2..3e838c01ef 100644 --- a/lib/core/src/lib/datatable/components/datatable-cell/datatable-cell.component.ts +++ b/lib/core/src/lib/datatable/components/datatable-cell/datatable-cell.component.ts @@ -117,14 +117,12 @@ export class DataTableCellComponent implements OnInit { if (this.tooltip) { return this.tooltip; } - const rawValue = value; const max = this.column?.maxTextLength; - if (typeof max === 'number' && max > 0 && rawValue.length > max) { + if (typeof max === 'number' && max > 0 && rawValue?.length > max) { return rawValue; } - return ''; } }