2020-03-11 04:52:08 +08:00
|
|
|
import { compile } from '../src'
|
|
|
|
|
2020-03-31 22:52:42 +08:00
|
|
|
describe('ssr compile: teleport', () => {
|
2020-03-11 04:52:08 +08:00
|
|
|
test('should work', () => {
|
2020-03-31 22:52:42 +08:00
|
|
|
expect(compile(`<teleport :target="target"><div/></teleport>`).code)
|
2020-03-11 04:52:08 +08:00
|
|
|
.toMatchInlineSnapshot(`
|
2020-03-31 22:52:42 +08:00
|
|
|
"const { ssrRenderTeleport: _ssrRenderTeleport } = require(\\"@vue/server-renderer\\")
|
2020-03-11 04:52:08 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
2020-03-31 22:52:42 +08:00
|
|
|
_ssrRenderTeleport(_push, (_push) => {
|
2020-03-11 04:52:08 +08:00
|
|
|
_push(\`<div></div>\`)
|
2020-03-28 11:45:50 +08:00
|
|
|
}, _ctx.target, false, _parent)
|
2020-03-11 04:52:08 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
2020-03-28 11:45:50 +08:00
|
|
|
|
|
|
|
test('disabled prop handling', () => {
|
2020-03-31 22:52:42 +08:00
|
|
|
expect(
|
|
|
|
compile(`<teleport :target="target" disabled><div/></teleport>`).code
|
|
|
|
).toMatchInlineSnapshot(`
|
2020-06-27 02:23:50 +08:00
|
|
|
"const { ssrRenderTeleport: _ssrRenderTeleport } = require(\\"@vue/server-renderer\\")
|
2020-03-28 11:45:50 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_ssrRenderTeleport(_push, (_push) => {
|
|
|
|
_push(\`<div></div>\`)
|
|
|
|
}, _ctx.target, true, _parent)
|
|
|
|
}"
|
|
|
|
`)
|
2020-03-28 11:45:50 +08:00
|
|
|
|
|
|
|
expect(
|
2020-03-31 22:52:42 +08:00
|
|
|
compile(`<teleport :target="target" :disabled="foo"><div/></teleport>`)
|
|
|
|
.code
|
2020-03-28 11:45:50 +08:00
|
|
|
).toMatchInlineSnapshot(`
|
2020-06-27 02:23:50 +08:00
|
|
|
"const { ssrRenderTeleport: _ssrRenderTeleport } = require(\\"@vue/server-renderer\\")
|
2020-03-28 11:45:50 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_ssrRenderTeleport(_push, (_push) => {
|
|
|
|
_push(\`<div></div>\`)
|
|
|
|
}, _ctx.target, _ctx.foo, _parent)
|
|
|
|
}"
|
|
|
|
`)
|
2020-03-28 11:45:50 +08:00
|
|
|
})
|
2020-03-11 04:52:08 +08:00
|
|
|
})
|