improve event listener test

This commit is contained in:
Rene Haas
2022-10-25 22:33:43 +02:00
parent cee980ddd7
commit 0c3d8a4b1b
@@ -349,6 +349,7 @@ describe('overlayscrollbars', () => {
const onUpdated = jest.fn(); const onUpdated = jest.fn();
const onUpdated2 = jest.fn(); const onUpdated2 = jest.fn();
const onDestroyed = jest.fn(); const onDestroyed = jest.fn();
const onScroll = jest.fn();
expect(onInitialized).not.toHaveBeenCalled(); expect(onInitialized).not.toHaveBeenCalled();
const osInstance = OverlayScrollbars( const osInstance = OverlayScrollbars(
@@ -358,6 +359,7 @@ describe('overlayscrollbars', () => {
initialized: onInitialized, initialized: onInitialized,
updated: [onUpdated, onUpdated, onUpdated2], updated: [onUpdated, onUpdated, onUpdated2],
destroyed: onDestroyed, destroyed: onDestroyed,
scroll: onScroll,
} }
); );
@@ -367,6 +369,14 @@ describe('overlayscrollbars', () => {
expect(onUpdated).toHaveBeenCalledTimes(1); expect(onUpdated).toHaveBeenCalledTimes(1);
expect(onUpdated2).toHaveBeenCalledTimes(1); expect(onUpdated2).toHaveBeenCalledTimes(1);
expect(onScroll).not.toHaveBeenCalled();
osInstance.elements().scrollEventElement.dispatchEvent(new Event('scroll'));
expect(onUpdated).toHaveBeenCalledTimes(1);
osInstance.off('scroll', onScroll);
osInstance.elements().scrollEventElement.dispatchEvent(new Event('scroll'));
expect(onUpdated).toHaveBeenCalledTimes(1);
osInstance.update(true); osInstance.update(true);
expect(onUpdated).toHaveBeenCalledTimes(2); expect(onUpdated).toHaveBeenCalledTimes(2);