2020-03-11 04:52:08 +08:00
|
|
|
import { compile } from '../src'
|
|
|
|
|
|
|
|
describe('ssr compile: suspense', () => {
|
|
|
|
test('implicit default', () => {
|
|
|
|
expect(compile(`<suspense><foo/></suspense>`).code).toMatchInlineSnapshot(`
|
2020-03-16 23:23:29 +08:00
|
|
|
"const { resolveComponent: _resolveComponent, withCtx: _withCtx } = require(\\"vue\\")
|
2020-03-11 04:52:08 +08:00
|
|
|
const { ssrRenderComponent: _ssrRenderComponent, ssrRenderSuspense: _ssrRenderSuspense } = require(\\"@vue/server-renderer\\")
|
|
|
|
|
|
|
|
return function ssrRender(_ctx, _push, _parent) {
|
|
|
|
const _component_foo = _resolveComponent(\\"foo\\")
|
|
|
|
|
2020-03-17 03:38:35 +08:00
|
|
|
_ssrRenderSuspense(_push, {
|
|
|
|
default: () => {
|
2020-03-11 04:52:08 +08:00
|
|
|
_push(_ssrRenderComponent(_component_foo, null, null, _parent))
|
|
|
|
},
|
|
|
|
_: 1
|
2020-03-17 03:38:35 +08:00
|
|
|
})
|
2020-03-11 04:52:08 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('explicit slots', () => {
|
|
|
|
expect(
|
|
|
|
compile(`<suspense>
|
|
|
|
<template #default>
|
|
|
|
<foo/>
|
|
|
|
</template>
|
|
|
|
<template #fallback>
|
|
|
|
loading...
|
|
|
|
</template>
|
|
|
|
</suspense>`).code
|
|
|
|
).toMatchInlineSnapshot(`
|
2020-03-16 23:23:29 +08:00
|
|
|
"const { resolveComponent: _resolveComponent, withCtx: _withCtx } = require(\\"vue\\")
|
2020-03-11 04:52:08 +08:00
|
|
|
const { ssrRenderComponent: _ssrRenderComponent, ssrRenderSuspense: _ssrRenderSuspense } = require(\\"@vue/server-renderer\\")
|
|
|
|
|
|
|
|
return function ssrRender(_ctx, _push, _parent) {
|
|
|
|
const _component_foo = _resolveComponent(\\"foo\\")
|
|
|
|
|
2020-03-17 03:38:35 +08:00
|
|
|
_ssrRenderSuspense(_push, {
|
|
|
|
default: () => {
|
2020-03-11 04:52:08 +08:00
|
|
|
_push(_ssrRenderComponent(_component_foo, null, null, _parent))
|
|
|
|
},
|
2020-03-17 03:38:35 +08:00
|
|
|
fallback: () => {
|
2020-03-11 04:52:08 +08:00
|
|
|
_push(\` loading... \`)
|
|
|
|
},
|
|
|
|
_: 1
|
2020-03-17 03:38:35 +08:00
|
|
|
})
|
2020-03-11 04:52:08 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
})
|