]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(teleport): test for accessing template ref inside teleport in mounted
authorEvan You <evan@vuejs.org>
Thu, 18 Jul 2024 13:15:27 +0000 (21:15 +0800)
committerEvan You <evan@vuejs.org>
Thu, 18 Jul 2024 13:15:27 +0000 (21:15 +0800)
packages/runtime-core/__tests__/components/Teleport.spec.ts

index 24400f6ed40a79e5118c99ae6bd61062a7f67d37..d2532a6db7c26903d40a5a3d24c85f8a79e8b221 100644 (file)
@@ -59,7 +59,7 @@ describe('renderer: teleport', () => {
           <div>
             <async />
             <teleport defer to="#target-suspense">
-              <div ref="tel">teleported</div>
+              <div>teleported</div>
             </teleport>
             <div id="target-suspense" />
           </div>
@@ -705,5 +705,27 @@ describe('renderer: teleport', () => {
       await nextTick()
       expect(root.innerHTML).toMatchInlineSnapshot('"<!--v-if-->"')
     })
+
+    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])
+    })
   }
 })