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?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With