fix(core): Account for addEventListener to be passed a Window or Document. (#57354)

This happened to work for other event listeners since both had a
addEventListener method.

PR Close #57354
This commit is contained in:
Thomas Nguyen
2024-08-06 14:45:05 -07:00
committed by Andrew Kushnir
parent 04911d7599
commit 8e945c7cc9
@@ -248,5 +248,31 @@ describe('event dispatch', () => {
bottomEl.click();
expect(onClickSpy).toHaveBeenCalledTimes(1);
});
it('should allow host listening on the window', async () => {
const onClickSpy = jasmine.createSpy();
@Component({
standalone: true,
selector: 'app',
template: `
<div id="top">
<div id="bottom"></div>
</div>
`,
})
class SimpleComponent {
renderer = inject(Renderer2);
destroy!: Function;
@HostListener('window:click', ['$event.target'])
listen(el: Element) {
onClickSpy();
}
}
configureTestingModule([SimpleComponent]);
fixture = TestBed.createComponent(SimpleComponent);
const nativeElement = fixture.debugElement.nativeElement;
const bottomEl = nativeElement.querySelector('#bottom')!;
bottomEl.click();
expect(onClickSpy).toHaveBeenCalledTimes(1);
});
});
});