I'm struggling with writing a Jasmine unit test for AddEventListener. How can I effectively test if the code for addEventListener is functioning correctly?
private static disableScrollingOnPageWhenPanelOpen(): void {
window.addEventListener('DOMMouseScroll', PhoneInputComponent.preventDefault, { passive: false });
window.addEventListener('mousewheel', PhoneInputComponent.preventDefault, { passive: false });
window.addEventListener('touchmove', PhoneInputComponent.preventDefault, { passive: false });}
I attempted to write a test but it didn't work as expected.
describe('disableScrollingOnPageWhenPanelOpen', () => {
it('should disable DOMMouseScroll', () => {
const e = new Event('DOMMouseScroll');
PhoneInputComponent['disableScrollingOnPageWhenPanelOpen']();
window.dispatchEvent(e);
spyOn(window, 'addEventListener').and.callThrough();
expect(window).toHaveBeenCalledWith('e',
PhoneInputComponent['preventDefault'], { passive: false });
});
If anyone could provide assistance on this matter, that would be greatly appreciated. I am attempting to verify if the addEventListener function has been properly called, but unsure if my testing method is correct.