From 4c03ab22249adea54a7214ed39d7918665ed395b Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 18 Jul 2024 21:15:27 +0800 Subject: [PATCH] test(teleport): test for accessing template ref inside teleport in mounted --- .../__tests__/components/Teleport.spec.ts | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/__tests__/components/Teleport.spec.ts b/packages/runtime-core/__tests__/components/Teleport.spec.ts index 24400f6ed4..d2532a6db7 100644 --- a/packages/runtime-core/__tests__/components/Teleport.spec.ts +++ b/packages/runtime-core/__tests__/components/Teleport.spec.ts @@ -59,7 +59,7 @@ describe('renderer: teleport', () => {
-
teleported
+
teleported
@@ -705,5 +705,27 @@ describe('renderer: teleport', () => { await nextTick() expect(root.innerHTML).toMatchInlineSnapshot('""') }) + + test('accessing template refs inside teleport', async () => { + const target = nodeOps.createElement('div') + const tRef = ref() + let tRefInMounted + + render( + h({ + render: () => [ + h(Teleport, { to: target }, h('div', { ref: tRef }, 'teleported')), + h('div', 'root'), + ], + mounted() { + tRefInMounted = tRef.value + }, + }), + nodeOps.createElement('div'), + ) + + // children[0] is the start anchor + expect(tRefInMounted).toBe(target.children[1]) + }) } }) -- 2.47.3