mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user