Angular: How I can test @HostListener in jasmine?
Testing for window:scroll:
it('should do something on window scroll', () => {
window.dispatchEvent(new Event('scroll'));
expect(...)....
});
You can try to make simple JS scroll by calling scrollTo
function on window.
In case you want to make scroll top it will be:
window.scrollTo(0, 0);
Update
var scrollEvent = document.createEvent('CustomEvent');
scrollEvent.initCustomEvent( 'scroll', false, false, null );
window.dispatchEvent(scrollEvent)