From f8caf137b6ad353f296c9f984579f9b0632a2ffc Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Sat, 19 May 2018 17:20:30 +0800 Subject: [PATCH] test: add back-top test --- components/back-top/__tests__/index.test.js | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 components/back-top/__tests__/index.test.js diff --git a/components/back-top/__tests__/index.test.js b/components/back-top/__tests__/index.test.js new file mode 100644 index 000000000..803b7d5e6 --- /dev/null +++ b/components/back-top/__tests__/index.test.js @@ -0,0 +1,27 @@ +import { mount } from '@vue/test-utils' +import BackTop from '..' + +describe('BackTop', () => { + beforeAll(() => { + jest.useFakeTimers() + }) + + afterAll(() => { + jest.useRealTimers() + }) + + it('should scroll to top after click it', () => { + const wrapper = mount(BackTop, { + propsData: { + visibilityHeight: -1, + }, + }) + document.documentElement.scrollTop = 400 + // trigger scroll manually + wrapper.vm.handleScroll() + jest.runAllTimers() + wrapper.find('.ant-back-top').trigger('click') + jest.runAllTimers() + expect(Math.abs(Math.round(document.documentElement.scrollTop))).toBe(0) + }) +})