mirror of
https://github.com/webslides/WebSlides.git
synced 2025-08-23 13:23:23 +02:00
Testing love
This commit is contained in:
@@ -7,17 +7,52 @@ beforeAll(() => {
|
||||
document.body.innerHTML = `<div id="webslides">${brs}</div>`;
|
||||
});
|
||||
|
||||
test('ScrollTo utility', () => {
|
||||
afterAll(() => {
|
||||
jest.clearAllTimers();
|
||||
});
|
||||
|
||||
test('ScrollTo with defaults', () => {
|
||||
const ws = document.getElementById('webslides');
|
||||
const cb = jest.fn();
|
||||
|
||||
scrollTo(100, 500, cb);
|
||||
scrollTo(100);
|
||||
|
||||
expect(cb).not.toBeCalled();
|
||||
expect(ws.scrollTop).toBe(0);
|
||||
|
||||
jest.runTimersToTime(400);
|
||||
|
||||
expect(ws.scrollTop).toBeLessThan(100);
|
||||
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(cb).toBeCalled();
|
||||
expect(ws.scrollTop).toBe(100);
|
||||
});
|
||||
|
||||
test('ScrollTo with custom duration', () => {
|
||||
const ws = document.getElementById('webslides');
|
||||
ws.scrollTop = 0;
|
||||
scrollTo(100, 2000);
|
||||
|
||||
expect(ws.scrollTop).toBe(0);
|
||||
jest.runTimersToTime(500);
|
||||
expect(ws.scrollTop).toBeLessThan(100);
|
||||
jest.runTimersToTime(700);
|
||||
expect(ws.scrollTop).toBeLessThan(100);
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(ws.scrollTop).toBe(100);
|
||||
});
|
||||
|
||||
test('ScrollTo with custom callback', () => {
|
||||
const ws = document.getElementById('webslides');
|
||||
ws.scrollTop = 0;
|
||||
const cb = jest.fn();
|
||||
|
||||
scrollTo(100, 500, cb);
|
||||
expect(ws.scrollTop).toBe(0);
|
||||
expect(cb).not.toBeCalled();
|
||||
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(ws.scrollTop).toBe(100);
|
||||
expect(cb).toBeCalled();
|
||||
});
|
||||
|
Reference in New Issue
Block a user