diff --git a/projects/igniteui-angular/src/lib/directives/text-highlight/text-highlight.directive.spec.ts b/projects/igniteui-angular/src/lib/directives/text-highlight/text-highlight.directive.spec.ts index bce041f6c69..a219dc4029a 100644 --- a/projects/igniteui-angular/src/lib/directives/text-highlight/text-highlight.directive.spec.ts +++ b/projects/igniteui-angular/src/lib/directives/text-highlight/text-highlight.directive.spec.ts @@ -299,6 +299,17 @@ describe('IgxHighlight', () => { expect(() => component.highlight.activateIfNecessary()).not.toThrowError(); }); + it('Should not throw when attempting to activate a non-existing group.', () => { + const fix = TestBed.createComponent(HighlightLoremIpsumComponent); + fix.detectChanges(); + + const component: HighlightLoremIpsumComponent = fix.debugElement.componentInstance; + component.highlightText('a'); + component.groupName = 'test1'; + fix.detectChanges(); + + expect(() => component.highlight.activateIfNecessary()).not.toThrowError(); + }); }); @Component({ diff --git a/projects/igniteui-angular/src/lib/directives/text-highlight/text-highlight.directive.ts b/projects/igniteui-angular/src/lib/directives/text-highlight/text-highlight.directive.ts index 23f5fcbf8b8..5407ca0d622 100644 --- a/projects/igniteui-angular/src/lib/directives/text-highlight/text-highlight.directive.ts +++ b/projects/igniteui-angular/src/lib/directives/text-highlight/text-highlight.directive.ts @@ -318,7 +318,7 @@ export class IgxTextHighlightDirective implements AfterViewInit, AfterViewChecke public activateIfNecessary(): void { const group = this.service.highlightGroupsMap.get(this.groupName); - if (group.index >= 0 && group.column === this.column && group.row === this.row && compareMaps(this.metadata, group.metadata)) { + if (group && group.index >= 0 && group.column === this.column && group.row === this.row && compareMaps(this.metadata, group.metadata)) { this.activate(group.index); } }