diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.spec.ts index 1fa2d5a0498..0e5fd417a4f 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.spec.ts @@ -87,10 +87,18 @@ describe('TableComponent', () => { }); it('should prevent propagation of mouseenter event', (done) => { - fixture.detectChanges(); + let wasCalled = false; const mouseEvent = new MouseEvent('mouseenter'); - mouseEvent.stopPropagation = () => done(); - fixture.debugElement.nativeElement.dispatchEvent(mouseEvent); + mouseEvent.stopPropagation = () => { + wasCalled = true; + }; + spyOn(window, 'addEventListener').and.callFake((eventName, fn) => { + fn(mouseEvent); + expect(eventName).toBe('mouseenter'); + expect(wasCalled).toBe(true); + done(); + }); + component.ngOnInit(); }); describe('test search', () => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts index ad94eeebae5..21c0dcd1421 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts @@ -179,14 +179,7 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O ngOnInit() { // ngx-datatable triggers calculations each time mouse enters a row, // this will prevent that. - window.addEventListener( - 'mouseenter', - function(event) { - event.stopPropagation(); - }, - true - ); - + window.addEventListener('mouseenter', (event) => event.stopPropagation(), true); this._addTemplates(); if (!this.sorts) { // Check whether the specified identifier exists.