diff --git a/packages/components/popper/__tests__/content.test.tsx b/packages/components/popper/__tests__/content.test.tsx index b4830af8a9..d46cc9fab8 100644 --- a/packages/components/popper/__tests__/content.test.tsx +++ b/packages/components/popper/__tests__/content.test.tsx @@ -1,4 +1,4 @@ -import { nextTick, ref } from 'vue' +import { defineComponent, nextTick, ref } from 'vue' import { mount } from '@vue/test-utils' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { POPPER_INJECTION_KEY } from '@element-plus/tokens' @@ -14,6 +14,21 @@ const popperInjection = { contentRef: ref(), } +const TestComponent = defineComponent({ + setup() { + return { + contentRef: ref(), + } + }, + render() { + return ( + + {AXIOM} + + ) + }, +}) + const mountContent = (props = {}) => mount({AXIOM}, { global: { @@ -23,6 +38,15 @@ const mountContent = (props = {}) => }, }) +const mountWrappedContent = (props = {}) => + mount(, { + global: { + provide: { + [POPPER_INJECTION_KEY as symbol]: popperInjection, + }, + }, + }) + describe('', () => { describe('with triggerRef provided', () => { const triggerKls = 'el-popper__trigger' @@ -48,8 +72,16 @@ describe('', () => { expect(wrapper.html()).toContain(AXIOM) expect(popperInjection.popperInstanceRef.value).toBeDefined() expect(wrapper.classes()).toEqual(['el-popper', 'is-dark']) + expect(wrapper.vm.contentStyle).toHaveLength(3) expect(wrapper.vm.contentStyle[0]).toHaveProperty('zIndex') - expect(wrapper.vm.contentStyle[1]).toBeUndefined() + expect(wrapper.vm.contentStyle[1]).toEqual({}) + expect(wrapper.vm.contentStyle[2]).toEqual( + expect.objectContaining({ + position: 'absolute', + top: '0', + left: '0', + }) + ) }) it('should be able to be pure and themed', async () => { @@ -94,7 +126,6 @@ describe('', () => { describe('instantiate popper instance', () => { it('should be able to update the current instance', async () => { - wrapper = mountContent() await nextTick() vi.spyOn( @@ -113,10 +144,11 @@ describe('', () => { }) it('should be able to update the reference node', async () => { - wrapper = mountContent() + const w = mountWrappedContent() await nextTick() - const oldInstance = wrapper.vm.popperInstanceRef + const { contentRef } = w.vm + const oldInstance = contentRef.popperInstanceRef const newRef = document.createElement('div') newRef.classList.add('new-ref') @@ -124,13 +156,13 @@ describe('', () => { popperInjection.triggerRef.value = newRef await nextTick() - expect(wrapper.vm.popperInstanceRef).not.toStrictEqual(oldInstance) + expect(contentRef.popperInstanceRef).not.toStrictEqual(oldInstance) popperInjection.triggerRef.value = undefined await nextTick() - expect(wrapper.vm.popperInstanceRef).toBeUndefined() + expect(contentRef.popperInstanceRef).toBeUndefined() }) }) }) diff --git a/packages/components/popper/src/arrow.vue b/packages/components/popper/src/arrow.vue index 7914b80e79..fb3aac4f74 100644 --- a/packages/components/popper/src/arrow.vue +++ b/packages/components/popper/src/arrow.vue @@ -1,5 +1,10 @@