Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 4c03ab2

Browse files
committed
test(teleport): test for accessing template ref inside teleport in mounted
1 parent 59a3e88 commit 4c03ab2

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

packages/runtime-core/__tests__/components/Teleport.spec.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('renderer: teleport', () => {
5959
<div>
6060
<async />
6161
<teleport defer to="#target-suspense">
62-
<div ref="tel">teleported</div>
62+
<div>teleported</div>
6363
</teleport>
6464
<div id="target-suspense" />
6565
</div>
@@ -705,5 +705,27 @@ describe('renderer: teleport', () => {
705705
await nextTick()
706706
expect(root.innerHTML).toMatchInlineSnapshot('"<!--v-if-->"')
707707
})
708+
709+
test('accessing template refs inside teleport', async () => {
710+
const target = nodeOps.createElement('div')
711+
const tRef = ref()
712+
let tRefInMounted
713+
714+
render(
715+
h({
716+
render: () => [
717+
h(Teleport, { to: target }, h('div', { ref: tRef }, 'teleported')),
718+
h('div', 'root'),
719+
],
720+
mounted() {
721+
tRefInMounted = tRef.value
722+
},
723+
}),
724+
nodeOps.createElement('div'),
725+
)
726+
727+
// children[0] is the start anchor
728+
expect(tRefInMounted).toBe(target.children[1])
729+
})
708730
}
709731
})

0 commit comments

Comments
 (0)