You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/back-top/__tests__/index.test.js

28 lines
639 B

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)
})
})