Skip to content

Commit

Permalink
✅ fix back-top test
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Dec 13, 2018
1 parent 8280c6d commit 3b8dd81
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions components/back-top/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,14 @@ import { mount } from 'enzyme';
import BackTop from '..';

describe('BackTop', () => {
beforeAll(() => {
jest.useFakeTimers();
});

afterAll(() => {
jest.useRealTimers();
});

it('should scroll to top after click it', async () => {
const wrapper = mount(<BackTop visibilityHeight={-1} />);
document.documentElement.scrollTop = 400;
// trigger scroll manually
wrapper.instance().handleScroll();
jest.runAllTimers();
wrapper.find('.ant-back-top').simulate('click');
jest.runAllTimers();
await new Promise(resolve => setTimeout(resolve, 0));
wrapper.find('.ant-back-top').simulate('click');
await new Promise(resolve => setTimeout(resolve, 1000));
expect(Math.abs(Math.round(document.documentElement.scrollTop))).toBe(0);
});
});

0 comments on commit 3b8dd81

Please sign in to comment.