2022-03-25 15:35:56 +08:00
|
|
|
import { h, inject, nextTick } from 'vue'
|
2021-09-17 15:27:31 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
2022-04-19 12:46:57 +08:00
|
|
|
import { describe, expect, it } from 'vitest'
|
2022-03-24 21:22:46 +08:00
|
|
|
import { POPPER_INJECTION_KEY } from '@element-plus/tokens'
|
2022-01-04 09:15:15 +08:00
|
|
|
import ElPopper from '../src/popper.vue'
|
2020-08-18 00:25:10 +08:00
|
|
|
|
2022-01-04 09:15:15 +08:00
|
|
|
const AXIOM = 'rem is the best girl'
|
2020-08-18 00:25:10 +08:00
|
|
|
|
2022-01-04 09:15:15 +08:00
|
|
|
const TestChild = {
|
|
|
|
template: `<div ref="contentRef">${AXIOM}</div>`,
|
2020-08-18 00:25:10 +08:00
|
|
|
|
2022-01-04 09:15:15 +08:00
|
|
|
setup() {
|
|
|
|
const { contentRef } = inject(POPPER_INJECTION_KEY, undefined)!
|
2020-08-18 18:02:28 +08:00
|
|
|
|
2022-01-04 09:15:15 +08:00
|
|
|
return {
|
|
|
|
contentRef,
|
|
|
|
}
|
|
|
|
},
|
2020-09-14 10:03:33 +08:00
|
|
|
}
|
2020-12-01 10:28:42 +08:00
|
|
|
|
2022-01-04 09:15:15 +08:00
|
|
|
describe('<ElPopper />', () => {
|
|
|
|
const mountPopper = () => {
|
|
|
|
return mount(ElPopper, {
|
2020-08-18 20:23:39 +08:00
|
|
|
slots: {
|
2022-01-04 09:15:15 +08:00
|
|
|
default: () => h(TestChild),
|
2020-08-18 20:23:39 +08:00
|
|
|
},
|
2020-08-18 00:25:10 +08:00
|
|
|
})
|
2022-01-04 09:15:15 +08:00
|
|
|
}
|
2020-08-28 10:47:02 +08:00
|
|
|
|
2022-01-04 09:15:15 +08:00
|
|
|
it('should be able to provide instance to its children', async () => {
|
|
|
|
const wrapper = mountPopper()
|
2020-09-14 10:03:33 +08:00
|
|
|
|
2022-01-04 09:15:15 +08:00
|
|
|
await nextTick()
|
2020-12-08 21:01:16 +08:00
|
|
|
|
2022-01-04 09:15:15 +08:00
|
|
|
expect(wrapper.vm.contentRef).not.toBe(null)
|
2022-03-24 21:22:46 +08:00
|
|
|
expect(wrapper.vm.contentRef!.innerHTML).toBe(AXIOM)
|
2020-08-28 10:47:02 +08:00
|
|
|
})
|
2020-08-18 00:25:10 +08:00
|
|
|
})
|