mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-05 05:28:20 +08:00
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
import scrollTo from '../scrollTo';
|
|
import { sleep } from '../../../tests/utils';
|
|
|
|
describe('Test ScrollTo function', () => {
|
|
it('test scrollTo', async () => {
|
|
const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => {
|
|
const w = window;
|
|
w.scrollY = y;
|
|
w.pageYOffset = y;
|
|
});
|
|
scrollTo(0, 1000);
|
|
await sleep(1000);
|
|
expect(window.pageYOffset).toBe(1000);
|
|
scrollToSpy.mockRestore();
|
|
});
|
|
|
|
it('test unknow easing funciton', () => {
|
|
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
scrollTo(0, 0, {
|
|
ease: 'ffff',
|
|
});
|
|
expect(warnSpy).toHaveBeenCalledWith('Unkonw easing funciton in scrollTo');
|
|
warnSpy.mockRestore();
|
|
});
|
|
|
|
it('test callback - option', async () => {
|
|
const cbMock = jest.fn();
|
|
scrollTo(0, 1000, {
|
|
callback: cbMock,
|
|
});
|
|
await sleep(1000);
|
|
expect(cbMock).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('test getContainer - option', async () => {
|
|
const div = document.createElement('div');
|
|
scrollTo(0, 1000, {
|
|
getContainer: () => div,
|
|
});
|
|
await sleep(1000);
|
|
expect(div.scrollTop).toBe(1000);
|
|
});
|
|
});
|