import { createSSRApp, h, ref, nextTick, VNode, Portal, createStaticVNode, Suspense, onMounted } from '@vue/runtime-dom' import { renderToString } from '@vue/server-renderer' import { mockWarn } from '@vue/shared' function mountWithHydration(html: string, render: () => any) { const container = document.createElement('div') container.innerHTML = html const app = createSSRApp({ render }) return { vnode: app.mount(container).$.subTree, container } } const triggerEvent = (type: string, el: Element) => { const event = new Event(type) el.dispatchEvent(event) } describe('SSR hydration', () => { mockWarn() test('text', async () => { const msg = ref('foo') const { vnode, container } = mountWithHydration('foo', () => msg.value) expect(vnode.el).toBe(container.firstChild) expect(container.textContent).toBe('foo') msg.value = 'bar' await nextTick() expect(container.textContent).toBe('bar') }) test('comment', () => { const { vnode, container } = mountWithHydration('', () => null) expect(vnode.el).toBe(container.firstChild) expect(vnode.el.nodeType).toBe(8) // comment }) test('static', () => { const html = '
bar