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

38 lines
822 B
TypeScript
Raw Normal View History

import { nextTick, h, inject } from 'vue'
import { mount } from '@vue/test-utils'
import ElPopper from '../src/popper.vue'
import { POPPER_INJECTION_KEY } from '../src/tokens'
2020-08-18 00:25:10 +08:00
const AXIOM = 'rem is the best girl'
2020-08-18 00:25:10 +08:00
const TestChild = {
template: `<div ref="contentRef">${AXIOM}</div>`,
2020-08-18 00:25:10 +08:00
setup() {
const { contentRef } = inject(POPPER_INJECTION_KEY, undefined)!
2020-08-18 18:02:28 +08:00
return {
contentRef,
}
},
2020-09-14 10:03:33 +08:00
}
describe('<ElPopper />', () => {
const mountPopper = () => {
return mount(ElPopper, {
slots: {
default: () => h(TestChild),
},
2020-08-18 00:25:10 +08:00
})
}
it('should be able to provide instance to its children', async () => {
const wrapper = mountPopper()
2020-09-14 10:03:33 +08:00
await nextTick()
expect(wrapper.vm.contentRef).not.toBe(null)
expect(wrapper.vm.contentRef.innerHTML).toBe(AXIOM)
})
2020-08-18 00:25:10 +08:00
})