mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-21 17:00:36 +03:00
add scroll event listener test
This commit is contained in:
@@ -302,17 +302,25 @@ 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();
|
||||||
const osInstance = OverlayScrollbars(div, {});
|
const osInstance = OverlayScrollbars(div, {});
|
||||||
|
|
||||||
osInstance.on('initialized', onInitialized);
|
osInstance.on('initialized', onInitialized);
|
||||||
osInstance.on('updated', [onUpdated, onUpdated, onUpdated2]);
|
osInstance.on('updated', [onUpdated, onUpdated, onUpdated2]);
|
||||||
osInstance.on('destroyed', onDestroyed);
|
osInstance.on('destroyed', onDestroyed);
|
||||||
|
osInstance.on('scroll', onScroll);
|
||||||
|
|
||||||
expect(onInitialized).not.toHaveBeenCalled();
|
expect(onInitialized).not.toHaveBeenCalled();
|
||||||
|
|
||||||
expect(onUpdated).not.toHaveBeenCalled();
|
expect(onUpdated).not.toHaveBeenCalled();
|
||||||
expect(onUpdated2).not.toHaveBeenCalled();
|
expect(onUpdated2).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
expect(onScroll).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
osInstance.elements().scrollEventElement.dispatchEvent(new Event('scroll'));
|
||||||
|
expect(onScroll).toHaveBeenCalledTimes(1);
|
||||||
|
expect(onScroll).toHaveBeenLastCalledWith(osInstance, expect.any(Object));
|
||||||
|
|
||||||
osInstance.update();
|
osInstance.update();
|
||||||
expect(onUpdated).not.toHaveBeenCalled();
|
expect(onUpdated).not.toHaveBeenCalled();
|
||||||
expect(onUpdated2).not.toHaveBeenCalled();
|
expect(onUpdated2).not.toHaveBeenCalled();
|
||||||
@@ -330,8 +338,10 @@ describe('overlayscrollbars', () => {
|
|||||||
|
|
||||||
// after destruction no further events are triggered
|
// after destruction no further events are triggered
|
||||||
osInstance.update(true);
|
osInstance.update(true);
|
||||||
|
osInstance.elements().scrollEventElement.dispatchEvent(new Event('scroll'));
|
||||||
expect(onUpdated).toHaveBeenCalledTimes(1);
|
expect(onUpdated).toHaveBeenCalledTimes(1);
|
||||||
expect(onUpdated2).toHaveBeenCalledTimes(1);
|
expect(onUpdated2).toHaveBeenCalledTimes(1);
|
||||||
|
expect(onScroll).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('off', () => {
|
test('off', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user