ant-design/components/back-top/__tests__/index.test.js

23 lines
704 B
JavaScript
Raw Normal View History

2017-07-07 16:29:03 +08:00
import React from 'react';
import { mount } from 'enzyme';
import { sleep } from '../../../tests/utils';
2017-07-07 16:29:03 +08:00
import BackTop from '..';
describe('BackTop', () => {
2018-12-14 00:23:39 +08:00
it('should scroll to top after click it', async () => {
2017-07-07 16:29:03 +08:00
const wrapper = mount(<BackTop visibilityHeight={-1} />);
const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => {
2019-08-06 21:45:46 +08:00
window.scrollY = y;
window.pageYOffset = y;
});
window.scrollTo(0, 400);
2017-07-07 16:29:03 +08:00
// trigger scroll manually
2017-09-20 16:26:18 +08:00
wrapper.instance().handleScroll();
2019-08-06 22:10:57 +08:00
await sleep();
2018-12-14 00:49:28 +08:00
wrapper.find('.ant-back-top').simulate('click');
2019-08-06 21:45:46 +08:00
await sleep(500);
expect(window.pageYOffset).toBe(0);
scrollToSpy.mockRestore();
2017-07-07 16:29:03 +08:00
});
});