element-plus/packages/components/tooltip/__tests__/tooltip.spec.ts

52 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-08-25 22:25:46 +08:00
import { h, nextTick } from 'vue'
import { mount } from '@vue/test-utils'
2020-09-14 10:03:33 +08:00
import Tooltip from '../src/index'
2020-08-25 22:25:46 +08:00
import type { VNode } from 'vue'
const AXIOM = 'Rem is the best girl'
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'
describe('Tooltip.vue', () => {
2020-08-25 22:25:46 +08:00
beforeEach(() => {
document.body.innerHTML = ''
})
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
)
2020-09-14 10:03:33 +08:00
// since VTU does not provide any functionality for testing teleported components
expect(document.querySelector(selector).getAttribute('style')).toContain(
'display: none'
)
2020-08-25 22:25:46 +08:00
await wrapper.setProps({
modelValue: true,
})
2020-08-25 22:25:46 +08:00
await nextTick()
expect(
document.querySelector(selector).getAttribute('style')
).not.toContain('display: none')
})
})