2020-02-05 10:03:16 +08:00
|
|
|
import { compile } from '../src'
|
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
function compileWithWrapper(src: string) {
|
|
|
|
return compile(`<div>${src}</div>`)
|
|
|
|
}
|
|
|
|
|
2020-02-05 10:03:16 +08:00
|
|
|
describe('ssr: v-show', () => {
|
2020-06-27 02:23:50 +08:00
|
|
|
test('basic as root', () => {
|
2020-02-05 10:03:16 +08:00
|
|
|
expect(compile(`<div v-show="foo"/>`).code).toMatchInlineSnapshot(`
|
2020-06-27 02:23:50 +08:00
|
|
|
"const { mergeProps: _mergeProps } = require(\\"vue\\")
|
|
|
|
const { ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")
|
|
|
|
|
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_push(\`<div\${_ssrRenderAttrs(_mergeProps({
|
|
|
|
style: (_ctx.foo) ? null : { display: \\"none\\" }
|
|
|
|
}, _attrs))}></div>\`)
|
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('basic', () => {
|
|
|
|
expect(compileWithWrapper(`<div v-show="foo"/>`).code)
|
|
|
|
.toMatchInlineSnapshot(`
|
|
|
|
"const { ssrRenderStyle: _ssrRenderStyle, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")
|
2020-02-05 10:03:16 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_push(\`<div\${
|
|
|
|
_ssrRenderAttrs(_attrs)
|
|
|
|
}><div style=\\"\${
|
|
|
|
_ssrRenderStyle((_ctx.foo) ? null : { display: \\"none\\" })
|
|
|
|
}\\"></div></div>\`)
|
2020-02-05 10:03:16 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('with static style', () => {
|
2020-06-27 02:23:50 +08:00
|
|
|
expect(compileWithWrapper(`<div style="color:red" v-show="foo"/>`).code)
|
2020-02-05 10:03:16 +08:00
|
|
|
.toMatchInlineSnapshot(`
|
2020-06-27 02:23:50 +08:00
|
|
|
"const { ssrRenderStyle: _ssrRenderStyle, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")
|
2020-02-05 10:03:16 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_push(\`<div\${
|
|
|
|
_ssrRenderAttrs(_attrs)
|
|
|
|
}><div style=\\"\${
|
|
|
|
_ssrRenderStyle([
|
|
|
|
{\\"color\\":\\"red\\"},
|
|
|
|
(_ctx.foo) ? null : { display: \\"none\\" }
|
|
|
|
])
|
|
|
|
}\\"></div></div>\`)
|
2020-02-05 10:03:16 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('with dynamic style', () => {
|
2020-06-27 02:23:50 +08:00
|
|
|
expect(
|
|
|
|
compileWithWrapper(`<div :style="{ color: 'red' }" v-show="foo"/>`).code
|
|
|
|
).toMatchInlineSnapshot(`
|
|
|
|
"const { ssrRenderStyle: _ssrRenderStyle, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")
|
2020-02-05 10:03:16 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_push(\`<div\${
|
|
|
|
_ssrRenderAttrs(_attrs)
|
|
|
|
}><div style=\\"\${
|
|
|
|
_ssrRenderStyle([
|
|
|
|
{ color: 'red' },
|
|
|
|
(_ctx.foo) ? null : { display: \\"none\\" }
|
|
|
|
])
|
|
|
|
}\\"></div></div>\`)
|
2020-02-05 10:03:16 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('with static + dynamic style', () => {
|
|
|
|
expect(
|
2020-06-27 02:23:50 +08:00
|
|
|
compileWithWrapper(
|
|
|
|
`<div style="color:red" :style="{ fontSize: 14 }" v-show="foo"/>`
|
|
|
|
).code
|
2020-02-05 10:03:16 +08:00
|
|
|
).toMatchInlineSnapshot(`
|
2020-06-27 02:23:50 +08:00
|
|
|
"const { ssrRenderStyle: _ssrRenderStyle, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")
|
2020-02-05 10:03:16 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_push(\`<div\${
|
|
|
|
_ssrRenderAttrs(_attrs)
|
|
|
|
}><div style=\\"\${
|
|
|
|
_ssrRenderStyle([
|
|
|
|
{\\"color\\":\\"red\\"},
|
|
|
|
{ fontSize: 14 },
|
|
|
|
(_ctx.foo) ? null : { display: \\"none\\" }
|
|
|
|
])
|
|
|
|
}\\"></div></div>\`)
|
2020-02-05 10:03:16 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('with v-bind', () => {
|
|
|
|
expect(
|
2020-06-27 02:23:50 +08:00
|
|
|
compileWithWrapper(
|
2020-02-05 10:03:16 +08:00
|
|
|
`<div v-bind="baz" style="color:red" :style="{ fontSize: 14 }" v-show="foo"/>`
|
|
|
|
).code
|
|
|
|
).toMatchInlineSnapshot(`
|
2020-02-08 08:04:55 +08:00
|
|
|
"const { mergeProps: _mergeProps } = require(\\"vue\\")
|
|
|
|
const { ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")
|
2020-02-05 10:03:16 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_push(\`<div\${
|
|
|
|
_ssrRenderAttrs(_attrs)
|
|
|
|
}><div\${
|
|
|
|
_ssrRenderAttrs(_mergeProps(_ctx.baz, {
|
|
|
|
style: [
|
|
|
|
{\\"color\\":\\"red\\"},
|
|
|
|
{ fontSize: 14 },
|
|
|
|
(_ctx.foo) ? null : { display: \\"none\\" }
|
|
|
|
]
|
|
|
|
}))
|
|
|
|
}></div></div>\`)
|
2020-02-05 10:03:16 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
})
|