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'
|
2020-09-14 10:03:33 +08:00
|
|
|
import Tooltip from '../src/index'
|
2020-08-24 15:38:30 +08:00
|
|
|
|
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'
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
const _mount = (props: any = {}, content: string | VNode = '') =>
|
|
|
|
mount(Tooltip, {
|
|
|
|
slots: {
|
|
|
|
default: () => h('div', AXIOM),
|
|
|
|
content: () => content,
|
|
|
|
},
|
|
|
|
props,
|
|
|
|
attachTo: 'body',
|
|
|
|
})
|
2020-08-25 22:25:46 +08:00
|
|
|
|
|
|
|
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 () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
{
|
|
|
|
manual: true,
|
|
|
|
modelValue: false,
|
|
|
|
},
|
|
|
|
AXIOM
|
|
|
|
)
|
2020-09-14 10:03:33 +08:00
|
|
|
// since VTU does not provide any functionality for testing teleported components
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(document.querySelector(selector).getAttribute('style')).toContain(
|
|
|
|
'display: none'
|
|
|
|
)
|
2020-08-25 22:25:46 +08:00
|
|
|
|
|
|
|
await wrapper.setProps({
|
|
|
|
modelValue: true,
|
2020-08-24 15:38:30 +08:00
|
|
|
})
|
2020-08-25 22:25:46 +08:00
|
|
|
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
document.querySelector(selector).getAttribute('style')
|
|
|
|
).not.toContain('display: none')
|
2020-08-24 15:38:30 +08:00
|
|
|
})
|
|
|
|
})
|