import { nextTick } from 'vue'
import { mount } from '@vue/test-utils'
import { CaretTop } from '@element-plus/icons-vue'
import Backtop from '../src/backtop.vue'
import type { VNode } from 'vue'
const _mount = (render: () => VNode) =>
mount(render, { attachTo: document.body })
describe('Backtop.vue', () => {
test('render', async () => {
const wrapper = _mount(() => (
))
await nextTick()
expect(wrapper.find('.el-backtop').exists()).toBe(false)
wrapper.element.scrollTop = 2000
await wrapper.trigger('scroll')
expect(wrapper.find('.el-backtop').exists()).toBe(true)
expect(wrapper.find('.el-backtop').attributes('style')).toBe(
'right: 100px; bottom: 200px;'
)
expect(wrapper.findComponent(CaretTop).exists()).toBe(true)
await wrapper.trigger('click')
expect(wrapper.emitted()).toBeDefined()
})
})