Skip to content

Commit 84f0353

Browse files
committed
test: hydration test case for component w/ teleport root
1 parent cdda49b commit 84f0353

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

packages/runtime-core/__tests__/hydration.spec.ts

+29
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,35 @@ describe('SSR hydration', () => {
366366
)
367367
})
368368

369+
test('Teleport (as component root)', () => {
370+
const teleportContainer = document.createElement('div')
371+
teleportContainer.id = 'teleport4'
372+
teleportContainer.innerHTML = `hello<!---->`
373+
document.body.appendChild(teleportContainer)
374+
375+
const wrapper = {
376+
render() {
377+
return h(Teleport, { to: '#teleport4' }, ['hello'])
378+
}
379+
}
380+
381+
const { vnode, container } = mountWithHydration(
382+
'<div><!--teleport start--><!--teleport end--><div></div></div>',
383+
() => h('div', [h(wrapper), h('div')])
384+
)
385+
expect(vnode.el).toBe(container.firstChild)
386+
// component el
387+
const wrapperVNode = (vnode as any).children[0]
388+
const tpStart = container.firstChild?.firstChild
389+
const tpEnd = tpStart?.nextSibling
390+
expect(wrapperVNode.el).toBe(tpStart)
391+
expect(wrapperVNode.component.subTree.el).toBe(tpStart)
392+
expect(wrapperVNode.component.subTree.anchor).toBe(tpEnd)
393+
// next node hydrate properly
394+
const nextVNode = (vnode as any).children[1]
395+
expect(nextVNode.el).toBe(container.firstChild?.lastChild)
396+
})
397+
369398
// compile SSR + client render fn from the same template & hydrate
370399
test('full compiler integration', async () => {
371400
const mounted: string[] = []

0 commit comments

Comments
 (0)