wip(srr): slot outlet

This commit is contained in:
Evan You
2020-02-05 21:04:40 -05:00
parent 7a63103a11
commit 9b3b6962df
14 changed files with 263 additions and 120 deletions

View File

@@ -7,11 +7,8 @@ import {
ComponentOptions
} from 'vue'
import { escapeHtml } from '@vue/shared'
import {
renderToString,
renderComponent,
renderSlot
} from '../src/renderToString'
import { renderToString, renderComponent } from '../src/renderToString'
import { renderSlot } from '../src/helpers/renderSlot'
describe('ssr: renderToString', () => {
test('should apply app context', async () => {
@@ -135,7 +132,16 @@ describe('ssr: renderToString', () => {
props: ['msg'],
ssrRender(ctx: any, push: any, parent: any) {
push(`<div class="child">`)
renderSlot(ctx.$slots.default, { msg: 'from slot' }, push, parent)
renderSlot(
ctx.$slots,
'default',
{ msg: 'from slot' },
() => {
push(`fallback`)
},
push,
parent
)
push(`</div>`)
}
}
@@ -169,6 +175,19 @@ describe('ssr: renderToString', () => {
`<!----><span>from slot</span><!---->` +
`</div></div>`
)
// test fallback
expect(
await renderToString(
createApp({
ssrRender(_ctx, push, parent) {
push(`<div>parent`)
push(renderComponent(Child, { msg: 'hello' }, null, parent))
push(`</div>`)
}
})
)
).toBe(`<div>parent<div class="child"><!---->fallback<!----></div></div>`)
})
test('nested components with vnode slots', async () => {
@@ -176,7 +195,14 @@ describe('ssr: renderToString', () => {
props: ['msg'],
ssrRender(ctx: any, push: any, parent: any) {
push(`<div class="child">`)
renderSlot(ctx.$slots.default, { msg: 'from slot' }, push, parent)
renderSlot(
ctx.$slots,
'default',
{ msg: 'from slot' },
null,
push,
parent
)
push(`</div>`)
}
}