2017-07-07 16:29:03 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import BackTop from '..';
|
|
|
|
|
|
|
|
describe('BackTop', () => {
|
2017-11-16 17:12:36 +08:00
|
|
|
beforeAll(() => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should scroll to top after click it', () => {
|
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();
|
2017-10-18 17:16:14 +08:00
|
|
|
jest.runAllTimers();
|
2017-07-07 16:29:03 +08:00
|
|
|
wrapper.find('.ant-back-top').simulate('click');
|
2017-10-18 17:16:14 +08:00
|
|
|
jest.runAllTimers();
|
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
|
|
|
});
|
|
|
|
});
|