From 1b12b404b04325e71aadb7846622b2ce10b56152 Mon Sep 17 00:00:00 2001 From: daiwei Date: Tue, 14 Jan 2025 09:24:31 +0800 Subject: [PATCH] test: add test case --- .../__tests__/components/Teleport.spec.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/packages/runtime-core/__tests__/components/Teleport.spec.ts b/packages/runtime-core/__tests__/components/Teleport.spec.ts index 79125cd04d..1cf83dd35d 100644 --- a/packages/runtime-core/__tests__/components/Teleport.spec.ts +++ b/packages/runtime-core/__tests__/components/Teleport.spec.ts @@ -719,6 +719,36 @@ describe('renderer: teleport', () => { expect(root.innerHTML).toBe('') }) + test('skip unmount children if teleport not disabled & target missing', async () => { + const root = document.createElement('div') + const childShow = ref(true) + + const Comp = { + setup() { + return () => h(Teleport, { to: null }, [h('div', 'foo')]) + }, + } + + const App = defineComponent({ + setup() { + return () => { + return h(Fragment, { key: 0 }, [ + childShow.value ? h(Comp) : createCommentVNode('v-if'), + ]) + } + }, + }) + + domRender(h(App), root) + expect('Invalid Teleport target: null').toHaveBeenWarned() + expect('Invalid Teleport target on mount').toHaveBeenWarned() + expect(root.innerHTML).toBe('') + + childShow.value = false + await nextTick() + expect(root.innerHTML).toBe('') + }) + test('accessing template refs inside teleport', async () => { const target = nodeOps.createElement('div') const tRef = ref() -- 2.47.2