title: How to test a scrollTop event in Angular 8 with Jest?
body: <p>I've been searching for a solution to test the scrollTop event for two days, but I haven't found a solution anywhere. All my attempts returned the same error ...</p>
  
  <pre><code>TypeError: Cannot read property 'scrollTop' of undefined
  </code></pre>
  
  <p><strong>header.component.ts</strong></p>
  
  <pre><code>@HostListener('window:scroll', ['$event'])
  onWindowScroll(): void {       
    if(document.scrollingElement.scrollTop &gt; 63){
      this.headerElement.classList.add('height-63');
    }else{
      this.headerElement.classList.remove('height-63');
    }
  }
  </code></pre>
  
  <p><strong>header.component.spec</strong></p>
  
  <pre><code>it('should test scrollTop', () =&gt; {
    window.scrollTo(0, 500);
    //document.scrollingElement.scrollTop = 500 --&gt; I already tried to set the scrollTop value
    fixture.detectChanges();
    component.onWindowScroll();    
    expect(fixture.debugElement.nativeElement.querySelector('.height-63')).toBeTruthy();    
  });
  </code></pre>