ant-design/components/back-top/__tests__/index.test.js
2017-11-16 17:12:36 +08:00

25 lines
624 B
JavaScript

import React from 'react';
import { mount } from 'enzyme';
import BackTop from '..';
describe('BackTop', () => {
beforeAll(() => {
jest.useFakeTimers();
});
afterAll(() => {
jest.useRealTimers();
});
it('should scroll to top after click it', () => {
const wrapper = mount(<BackTop visibilityHeight={-1} />);
document.documentElement.scrollTop = 400;
// trigger scroll manually
wrapper.node.handleScroll();
jest.runAllTimers();
wrapper.find('.ant-back-top').simulate('click');
jest.runAllTimers();
expect(Math.round(document.documentElement.scrollTop)).toBe(0);
});
});