2020-08-25 22:25:46 +08:00
|
|
|
import { h, nextTick } from 'vue'
|
2020-08-24 15:38:30 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
|
|
|
import Tooltip from '../src/index.vue'
|
|
|
|
|
2020-08-25 22:25:46 +08:00
|
|
|
import type { VNode } from 'vue'
|
|
|
|
|
2020-08-24 15:38:30 +08:00
|
|
|
const AXIOM = 'Rem is the best girl'
|
|
|
|
|
2020-08-25 22:25:46 +08:00
|
|
|
const _mount = (props: any = {}, content: string | VNode = '') => mount(Tooltip, {
|
|
|
|
slots: {
|
|
|
|
default: () => h('div', AXIOM),
|
|
|
|
content: () => content,
|
|
|
|
},
|
|
|
|
props,
|
|
|
|
})
|
|
|
|
|
|
|
|
const selector = '.el-popper'
|
2020-08-24 15:38:30 +08:00
|
|
|
describe('Tooltip.vue', () => {
|
2020-08-25 22:25:46 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
document.body.innerHTML = ''
|
|
|
|
})
|
2020-08-24 15:38:30 +08:00
|
|
|
test('render test', () => {
|
2020-08-25 22:25:46 +08:00
|
|
|
const wrapper = _mount(undefined, AXIOM)
|
|
|
|
expect(wrapper.html()).toContain(AXIOM)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('manual mode', async () => {
|
|
|
|
const wrapper = _mount({
|
|
|
|
manual: true,
|
|
|
|
modelValue: false,
|
|
|
|
}, AXIOM)
|
|
|
|
// since VTU does not provide any functionality for testing teleporting components
|
|
|
|
expect(document.querySelector(selector).getAttribute('style')).toContain('display: none')
|
|
|
|
|
|
|
|
await wrapper.setProps({
|
|
|
|
modelValue: true,
|
2020-08-24 15:38:30 +08:00
|
|
|
})
|
2020-08-25 22:25:46 +08:00
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
expect(document.querySelector(selector).getAttribute('style')).not.toContain('display: none')
|
2020-08-24 15:38:30 +08:00
|
|
|
})
|
|
|
|
})
|