wip(hydration): hydrate multi-element static nodes

This commit is contained in:
Evan You
2020-05-15 16:30:20 -04:00
parent 1184118d23
commit dc229bcda4
2 changed files with 34 additions and 2 deletions

View File

@@ -56,10 +56,31 @@ describe('SSR hydration', () => {
test('static', () => {
const html = '<div><span>hello</span></div>'
const { vnode, container } = mountWithHydration(html, () =>
createStaticVNode(html)
createStaticVNode('', 1)
)
expect(vnode.el).toBe(container.firstChild)
expect(vnode.el.outerHTML).toBe(html)
expect(vnode.anchor).toBe(container.firstChild)
expect(vnode.children).toBe(html)
})
test('static (multiple elements)', () => {
const staticContent = '<div></div><span>hello</span>'
const html = `<div><div>hi</div>` + staticContent + `<div>ho</div></div>`
const n1 = h('div', 'hi')
const s = createStaticVNode('', 2)
const n2 = h('div', 'ho')
const { container } = mountWithHydration(html, () => h('div', [n1, s, n2]))
const div = container.firstChild!
expect(n1.el).toBe(div.firstChild)
expect(n2.el).toBe(div.lastChild)
expect(s.el).toBe(div.childNodes[1])
expect(s.anchor).toBe(div.childNodes[2])
expect(s.children).toBe(staticContent)
})
test('element with text children', async () => {