feat(ssr): serverPrefetch

This commit is contained in:
Evan You
2020-09-01 22:52:46 -04:00
parent 63f1f18064
commit c73b4a0e10
4 changed files with 55 additions and 5 deletions

View File

@@ -14,6 +14,7 @@ import { escapeHtml } from '@vue/shared'
import { renderToString } from '../src/renderToString'
import { ssrRenderSlot, SSRSlot } from '../src/helpers/ssrRenderSlot'
import { ssrRenderComponent } from '../src/helpers/ssrRenderComponent'
describe('ssr: renderToString', () => {
test('should apply app context', async () => {
const app = createApp({
@@ -580,4 +581,23 @@ describe('ssr: renderToString', () => {
).toHaveBeenWarned()
})
})
test('serverPrefetch', async () => {
const msg = Promise.resolve('hello')
const app = createApp({
data() {
return {
msg: ''
}
},
async serverPrefetch() {
this.msg = await msg
},
render() {
return h('div', this.msg)
}
})
const html = await renderToString(app)
expect(html).toBe(`<div>hello</div>`)
})
})