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

17 lines
610 B
JavaScript
Raw Normal View History

2017-07-07 16:29:03 +08:00
import React from 'react';
import { mount } from 'enzyme';
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} />);
document.documentElement.scrollTop = 400;
// trigger scroll manually
2017-09-20 16:26:18 +08:00
wrapper.instance().handleScroll();
2018-12-14 00:23:39 +08:00
await new Promise(resolve => setTimeout(resolve, 0));
2018-12-14 00:49:28 +08:00
wrapper.find('.ant-back-top').simulate('click');
await new Promise(resolve => setTimeout(resolve, 1000));
2018-03-06 21:47:05 +08:00
expect(Math.abs(Math.round(document.documentElement.scrollTop))).toBe(0);
2017-07-07 16:29:03 +08:00
});
});