vue3-yuanma/packages/compiler-ssr/__tests__/ssrSlotOutlet.spec.ts

61 lines
2.0 KiB
TypeScript
Raw Normal View History

2020-02-06 10:04:40 +08:00
import { compile } from '../src'
describe('ssr: <slot>', () => {
test('basic', () => {
expect(compile(`<slot/>`).code).toMatchInlineSnapshot(`
"const { ssrRenderSlot: _ssrRenderSlot } = require(\\"@vue/server-renderer\\")
2020-02-06 10:04:40 +08:00
return function ssrRender(_ctx, _push, _parent, _attrs) {
2020-02-07 01:09:09 +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(`
"const { ssrRenderSlot: _ssrRenderSlot } = require(\\"@vue/server-renderer\\")
2020-02-06 10:04:40 +08:00
return function ssrRender(_ctx, _push, _parent, _attrs) {
2020-02-07 01:09:09 +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(`
"const { ssrRenderSlot: _ssrRenderSlot } = require(\\"@vue/server-renderer\\")
2020-02-06 10:04:40 +08:00
return function ssrRender(_ctx, _push, _parent, _attrs) {
2020-02-07 01:09:09 +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(`
"const { ssrRenderSlot: _ssrRenderSlot } = require(\\"@vue/server-renderer\\")
2020-02-06 10:04:40 +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\\"
}, null, _push, _parent)
}"
`)
})
test('with fallback', () => {
expect(compile(`<slot>some {{ fallback }} content</slot>`).code)
.toMatchInlineSnapshot(`
"const { ssrRenderSlot: _ssrRenderSlot, ssrInterpolate: _ssrInterpolate } = require(\\"@vue/server-renderer\\")
2020-02-06 10:04:40 +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\`)
2020-02-06 10:04:40 +08:00
}, _push, _parent)
}"
`)
})
})