You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/back-top/__tests__/index.test.js

46 lines
1.3 KiB

import { mount } from '@vue/test-utils';
import BackTop from '..';
import { sleep } from '../../../tests/utils';
describe('BackTop', () => {
it('should scroll to top after click it', async () => {
const wrapper = mount(BackTop, {
props: {
visibilityHeight: -1,
},
});
const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => {
window.scrollY = y;
window.pageYOffset = y;
});
window.scrollTo(0, 400);
// trigger scroll manually
wrapper.vm.handleScroll();
await sleep();
wrapper.find('.ant-back-top').trigger('click');
await sleep(500);
expect(window.pageYOffset).toBe(0);
scrollToSpy.mockRestore();
});
it('support onClick', async () => {
const onClick = jest.fn();
const wrapper = mount(BackTop, {
props: {
visibilityHeight: -1,
onClick,
},
});
const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => {
window.scrollY = y;
window.pageYOffset = y;
});
window.scrollTo(0, 400);
// trigger scroll manually
wrapper.vm.handleScroll();
await sleep();
wrapper.find('.ant-back-top').trigger('click');
expect(onClick).toHaveBeenCalled();
scrollToSpy.mockRestore();
});
});