2020-02-06 10:04:40 +08:00
|
|
|
import { compile } from '../src'
|
|
|
|
|
|
|
|
describe('ssr: <slot>', () => {
|
|
|
|
test('basic', () => {
|
|
|
|
expect(compile(`<slot/>`).code).toMatchInlineSnapshot(`
|
2020-02-08 08:04:55 +08:00
|
|
|
"const { ssrRenderSlot: _ssrRenderSlot } = require(\\"@vue/server-renderer\\")
|
2020-02-06 10:04:40 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
2021-03-06 01:12:49 +08:00
|
|
|
_ssrRenderSlot(_ctx.$slots, \\"default\\", {}, null, _push, _parent)
|
2020-02-06 10:04:40 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('with name', () => {
|
|
|
|
expect(compile(`<slot name="foo" />`).code).toMatchInlineSnapshot(`
|
2020-02-08 08:04:55 +08:00
|
|
|
"const { ssrRenderSlot: _ssrRenderSlot } = require(\\"@vue/server-renderer\\")
|
2020-02-06 10:04:40 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
2021-03-06 01:12:49 +08:00
|
|
|
_ssrRenderSlot(_ctx.$slots, \\"foo\\", {}, null, _push, _parent)
|
2020-02-06 10:04:40 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('with dynamic name', () => {
|
|
|
|
expect(compile(`<slot :name="bar.baz" />`).code).toMatchInlineSnapshot(`
|
2020-02-08 08:04:55 +08:00
|
|
|
"const { ssrRenderSlot: _ssrRenderSlot } = require(\\"@vue/server-renderer\\")
|
2020-02-06 10:04:40 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
2021-03-06 01:12:49 +08:00
|
|
|
_ssrRenderSlot(_ctx.$slots, _ctx.bar.baz, {}, null, _push, _parent)
|
2020-02-06 10:04:40 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('with props', () => {
|
|
|
|
expect(compile(`<slot name="foo" :p="1" bar="2" />`).code)
|
|
|
|
.toMatchInlineSnapshot(`
|
2020-02-08 08:04:55 +08:00
|
|
|
"const { ssrRenderSlot: _ssrRenderSlot } = require(\\"@vue/server-renderer\\")
|
2020-02-06 10:04:40 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
2020-02-07 01:09:09 +08:00
|
|
|
_ssrRenderSlot(_ctx.$slots, \\"foo\\", {
|
2020-02-06 10:04:40 +08:00
|
|
|
p: 1,
|
|
|
|
bar: \\"2\\"
|
2021-03-06 01:12:49 +08:00
|
|
|
}, null, _push, _parent)
|
2020-02-06 10:04:40 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('with fallback', () => {
|
|
|
|
expect(compile(`<slot>some {{ fallback }} content</slot>`).code)
|
|
|
|
.toMatchInlineSnapshot(`
|
2020-02-08 08:04:55 +08:00
|
|
|
"const { ssrRenderSlot: _ssrRenderSlot, ssrInterpolate: _ssrInterpolate } = require(\\"@vue/server-renderer\\")
|
2020-02-06 10:04:40 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
2020-02-07 01:09:09 +08:00
|
|
|
_ssrRenderSlot(_ctx.$slots, \\"default\\", {}, () => {
|
|
|
|
_push(\`some \${_ssrInterpolate(_ctx.fallback)} content\`)
|
2021-03-06 01:12:49 +08:00
|
|
|
}, _push, _parent)
|
2021-03-06 00:10:06 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('with scopeId', async () => {
|
|
|
|
expect(
|
|
|
|
compile(`<slot/>`, {
|
|
|
|
scopeId: 'hello'
|
|
|
|
}).code
|
|
|
|
).toMatchInlineSnapshot(`
|
|
|
|
"const { ssrRenderSlot: _ssrRenderSlot } = require(\\"@vue/server-renderer\\")
|
|
|
|
|
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_ssrRenderSlot(_ctx.$slots, \\"default\\", {}, null, _push, _parent, \\"hello-s\\")
|
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
2021-03-06 01:12:49 +08:00
|
|
|
test('with scopeId + slotted:false', async () => {
|
|
|
|
expect(
|
|
|
|
compile(`<slot/>`, {
|
|
|
|
scopeId: 'hello',
|
|
|
|
slotted: false
|
|
|
|
}).code
|
|
|
|
).toMatchInlineSnapshot(`
|
|
|
|
"const { ssrRenderSlot: _ssrRenderSlot } = require(\\"@vue/server-renderer\\")
|
|
|
|
|
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_ssrRenderSlot(_ctx.$slots, \\"default\\", {}, null, _push, _parent)
|
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
2021-03-06 00:10:06 +08:00
|
|
|
test('with forwarded scopeId', async () => {
|
|
|
|
expect(
|
|
|
|
compile(`<Comp><slot/></Comp>`, {
|
|
|
|
scopeId: 'hello'
|
|
|
|
}).code
|
|
|
|
).toMatchInlineSnapshot(`
|
|
|
|
"const { resolveComponent: _resolveComponent, withCtx: _withCtx, renderSlot: _renderSlot } = require(\\"vue\\")
|
|
|
|
const { ssrRenderSlot: _ssrRenderSlot, ssrRenderComponent: _ssrRenderComponent } = require(\\"@vue/server-renderer\\")
|
|
|
|
|
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
const _component_Comp = _resolveComponent(\\"Comp\\")
|
|
|
|
|
|
|
|
_push(_ssrRenderComponent(_component_Comp, _attrs, {
|
|
|
|
default: _withCtx((_, _push, _parent, _scopeId) => {
|
|
|
|
if (_push) {
|
|
|
|
_ssrRenderSlot(_ctx.$slots, \\"default\\", {}, null, _push, _parent, \\"hello-s\\" + _scopeId)
|
|
|
|
} else {
|
|
|
|
return [
|
2021-03-06 01:12:49 +08:00
|
|
|
_renderSlot(_ctx.$slots, \\"default\\", {}, undefined, true)
|
2021-03-06 00:10:06 +08:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
_: 3 /* FORWARDED */
|
|
|
|
}, _parent))
|
2020-02-06 10:04:40 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
})
|