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

43 lines
1.1 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'
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'
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
2020-08-25 22:25:46 +08:00
expect(document.querySelector(selector).getAttribute('style')).toContain('display: none')
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')
})
})