Angular: How I can test @HostListener in jasmine?

Viewed 9315

I have the next code in angular's component:

@HostListener('window:scroll', []) onWindowScroll() {
  this.showScrollToTop = false;
}

How can I test this in jasmine? How to to initiate window scroll event?

3 Answers
 it('Focus over elements', () => {
    fixture.detectChanges();
    const event = new Event('click', { bubbles: true });
    const spyDocumentClick = spyOn(component, 'clickout').and.callThrough();
    component.clickout(event);
    expect(spyDocumentClick).toHaveBeenCalled();
 });
Related