Skip to content

Commit

Permalink
test: hydration test case for component w/ teleport root
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 18, 2022
1 parent cdda49b commit 84f0353
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/runtime-core/__tests__/hydration.spec.ts
Expand Up @@ -366,6 +366,35 @@ describe('SSR hydration', () => {
)
})

test('Teleport (as component root)', () => {
const teleportContainer = document.createElement('div')
teleportContainer.id = 'teleport4'
teleportContainer.innerHTML = `hello<!---->`
document.body.appendChild(teleportContainer)

const wrapper = {
render() {
return h(Teleport, { to: '#teleport4' }, ['hello'])
}
}

const { vnode, container } = mountWithHydration(
'<div><!--teleport start--><!--teleport end--><div></div></div>',
() => h('div', [h(wrapper), h('div')])
)
expect(vnode.el).toBe(container.firstChild)
// component el
const wrapperVNode = (vnode as any).children[0]
const tpStart = container.firstChild?.firstChild
const tpEnd = tpStart?.nextSibling
expect(wrapperVNode.el).toBe(tpStart)
expect(wrapperVNode.component.subTree.el).toBe(tpStart)
expect(wrapperVNode.component.subTree.anchor).toBe(tpEnd)
// next node hydrate properly
const nextVNode = (vnode as any).children[1]
expect(nextVNode.el).toBe(container.firstChild?.lastChild)
})

// compile SSR + client render fn from the same template & hydrate
test('full compiler integration', async () => {
const mounted: string[] = []
Expand Down

0 comments on commit 84f0353

Please sign in to comment.