2020-03-11 03:23:14 +08:00
|
|
|
import { createApp, h, Portal } from 'vue'
|
2020-02-27 03:59:53 +08:00
|
|
|
import { renderToString, SSRContext } from '../src/renderToString'
|
|
|
|
import { ssrRenderPortal } from '../src/helpers/ssrRenderPortal'
|
|
|
|
|
|
|
|
describe('ssrRenderPortal', () => {
|
2020-03-11 03:23:14 +08:00
|
|
|
test('portal rendering (compiled)', async () => {
|
2020-02-27 03:59:53 +08:00
|
|
|
const ctx = {
|
|
|
|
portals: {}
|
|
|
|
} as SSRContext
|
|
|
|
await renderToString(
|
|
|
|
createApp({
|
|
|
|
data() {
|
|
|
|
return { msg: 'hello' }
|
|
|
|
},
|
|
|
|
ssrRender(_ctx, _push, _parent) {
|
|
|
|
ssrRenderPortal(
|
|
|
|
_push => {
|
|
|
|
_push(`<div>content</div>`)
|
|
|
|
},
|
|
|
|
'#target',
|
|
|
|
_parent
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
ctx
|
|
|
|
)
|
|
|
|
expect(ctx.portals!['#target']).toBe(`<div>content</div>`)
|
|
|
|
})
|
2020-03-11 03:23:14 +08:00
|
|
|
|
|
|
|
test('portal rendering (vnode)', async () => {
|
|
|
|
const ctx: SSRContext = {}
|
|
|
|
await renderToString(
|
|
|
|
h(
|
|
|
|
Portal,
|
|
|
|
{
|
|
|
|
target: `#target`
|
|
|
|
},
|
|
|
|
h('span', 'hello')
|
|
|
|
),
|
|
|
|
ctx
|
|
|
|
)
|
|
|
|
expect(ctx.portals!['#target']).toBe('<span>hello</span>')
|
|
|
|
})
|
2020-02-27 03:59:53 +08:00
|
|
|
})
|