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