diff --git a/packages/components/popper/__tests__/arrow.test.ts b/packages/components/popper/__tests__/arrow.test.tsx similarity index 89% rename from packages/components/popper/__tests__/arrow.test.ts rename to packages/components/popper/__tests__/arrow.test.tsx index 2181f08ecf..3ec6f1a65f 100644 --- a/packages/components/popper/__tests__/arrow.test.ts +++ b/packages/components/popper/__tests__/arrow.test.tsx @@ -1,10 +1,11 @@ import { nextTick, ref } from 'vue' -import { shallowMount } from '@vue/test-utils' +import { mount } from '@vue/test-utils' import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { POPPER_CONTENT_INJECTION_KEY } from '@element-plus/tokens' import ElArrow from '../src/arrow.vue' import type { VueWrapper } from '@vue/test-utils' +import type { PopperArrowInstance } from '../src/arrow' const popperContentInjection = { arrowRef: ref(null), @@ -12,7 +13,7 @@ const popperContentInjection = { } const mountArrow = () => - shallowMount(ElArrow, { + mount(, { global: { provide: { [POPPER_CONTENT_INJECTION_KEY as symbol]: popperContentInjection, @@ -21,7 +22,7 @@ const mountArrow = () => }) describe('', () => { - let wrapper: VueWrapper> + let wrapper: VueWrapper beforeEach(() => { wrapper = mountArrow() diff --git a/packages/components/popper/__tests__/content.test.ts b/packages/components/popper/__tests__/content.test.tsx similarity index 94% rename from packages/components/popper/__tests__/content.test.ts rename to packages/components/popper/__tests__/content.test.tsx index eb929bef07..b4830af8a9 100644 --- a/packages/components/popper/__tests__/content.test.ts +++ b/packages/components/popper/__tests__/content.test.tsx @@ -4,6 +4,9 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { POPPER_INJECTION_KEY } from '@element-plus/tokens' import ElContent from '../src/content.vue' +import type { VueWrapper } from '@vue/test-utils' +import type { PopperContentInstance } from '../src/content' + const AXIOM = 'rem is the best girl' const popperInjection = { triggerRef: ref(), @@ -12,11 +15,7 @@ const popperInjection = { } const mountContent = (props = {}) => - mount(ElContent, { - props, - slots: { - default: () => AXIOM, - }, + mount({AXIOM}, { global: { provide: { [POPPER_INJECTION_KEY as symbol]: popperInjection, @@ -27,7 +26,8 @@ const mountContent = (props = {}) => describe('', () => { describe('with triggerRef provided', () => { const triggerKls = 'el-popper__trigger' - let wrapper: ReturnType + let wrapper: VueWrapper + beforeEach(() => { const trigger = document.createElement('div') trigger.className = triggerKls diff --git a/packages/components/popper/__tests__/popper.test.ts b/packages/components/popper/__tests__/popper.test.tsx similarity index 63% rename from packages/components/popper/__tests__/popper.test.ts rename to packages/components/popper/__tests__/popper.test.tsx index 08c42970a6..ed21124ba8 100644 --- a/packages/components/popper/__tests__/popper.test.ts +++ b/packages/components/popper/__tests__/popper.test.tsx @@ -1,4 +1,4 @@ -import { h, inject, nextTick } from 'vue' +import { defineComponent, inject, nextTick } from 'vue' import { mount } from '@vue/test-utils' import { describe, expect, it } from 'vitest' import { POPPER_INJECTION_KEY } from '@element-plus/tokens' @@ -6,29 +6,20 @@ import ElPopper from '../src/popper.vue' const AXIOM = 'rem is the best girl' -const TestChild = { - template: `
${AXIOM}
`, - +const TestChild = defineComponent({ setup() { const { contentRef } = inject(POPPER_INJECTION_KEY, undefined)! - - return { - contentRef, - } + return () =>
{AXIOM}
}, -} +}) describe('', () => { - const mountPopper = () => { - return mount(ElPopper, { - slots: { - default: () => h(TestChild), - }, - }) - } - it('should be able to provide instance to its children', async () => { - const wrapper = mountPopper() + const wrapper = mount( + + + + ) await nextTick() diff --git a/packages/components/popper/__tests__/trigger.test.ts b/packages/components/popper/__tests__/trigger.test.tsx similarity index 89% rename from packages/components/popper/__tests__/trigger.test.ts rename to packages/components/popper/__tests__/trigger.test.tsx index 6e7b4d8377..4410990322 100644 --- a/packages/components/popper/__tests__/trigger.test.ts +++ b/packages/components/popper/__tests__/trigger.test.tsx @@ -4,18 +4,19 @@ import { afterEach, describe, expect, it, vi } from 'vitest' import { POPPER_INJECTION_KEY } from '@element-plus/tokens' import ElTrigger from '../src/trigger.vue' +import type { VueWrapper } from '@vue/test-utils' +import type { PopperTriggerInstance } from '../src/trigger' + const AXIOM = 'rem is the best girl' + const popperInjection = { triggerRef: ref(null), popperInstanceRef: ref(null), contentRef: ref(null), } + const mountTrigger = (props = {}) => - mount(ElTrigger, { - props, - slots: { - default: () => AXIOM, - }, + mount({AXIOM}, { global: { provide: { [POPPER_INJECTION_KEY as symbol]: popperInjection, @@ -24,7 +25,7 @@ const mountTrigger = (props = {}) => }) describe('', () => { - let wrapper: ReturnType + let wrapper: VueWrapper afterEach(() => { popperInjection.triggerRef.value = null