mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-12 15:19:58 +08:00
a3077e449e
* chore: rm unnecessary React.useMemo
* Revert "chore: reset commit"
This reverts commit 2fa5df5185
.
* test: rm unnecessary async
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import getScroll from '../getScroll';
|
|
|
|
describe('getScroll', () => {
|
|
it('getScroll target null', () => {
|
|
expect(getScroll(null, true)).toBe(0);
|
|
expect(getScroll(null, false)).toBe(0);
|
|
});
|
|
|
|
it('getScroll window', () => {
|
|
const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => {
|
|
window.pageXOffset = x;
|
|
window.pageYOffset = y;
|
|
});
|
|
window.scrollTo(200, 400);
|
|
expect(getScroll(window, true)).toBe(400);
|
|
expect(getScroll(window, false)).toBe(200);
|
|
scrollToSpy.mockRestore();
|
|
});
|
|
|
|
it('getScroll document', () => {
|
|
const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => {
|
|
document.documentElement.scrollLeft = x;
|
|
document.documentElement.scrollTop = y;
|
|
});
|
|
window.scrollTo(200, 400);
|
|
expect(getScroll(document, true)).toBe(400);
|
|
expect(getScroll(document, false)).toBe(200);
|
|
scrollToSpy.mockRestore();
|
|
});
|
|
|
|
it('getScroll div', () => {
|
|
const div = document.createElement('div');
|
|
const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => {
|
|
div.scrollLeft = x;
|
|
div.scrollTop = y;
|
|
});
|
|
window.scrollTo(200, 400);
|
|
expect(getScroll(div, true)).toBe(400);
|
|
expect(getScroll(div, false)).toBe(200);
|
|
scrollToSpy.mockRestore();
|
|
});
|
|
|
|
it('getScroll documentElement', () => {
|
|
const div: any = {};
|
|
const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => {
|
|
div.scrollLeft = null;
|
|
div.scrollTop = null;
|
|
div.documentElement = {};
|
|
div.documentElement.scrollLeft = x;
|
|
div.documentElement.scrollTop = y;
|
|
});
|
|
window.scrollTo(200, 400);
|
|
expect(getScroll(div, true)).toBe(400);
|
|
expect(getScroll(div, false)).toBe(200);
|
|
scrollToSpy.mockRestore();
|
|
});
|
|
});
|