| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- import { compile } from '../src'
- function compileWithWrapper(src: string) {
- return compile(`<div>${src}</div>`)
- }
- describe('ssr: v-show', () => {
- test('basic as root', () => {
- expect(compile(`<div v-show="foo"/>`).code).toMatchInlineSnapshot(`
- "const { mergeProps: _mergeProps } = require("vue")
- const { ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
- return function ssrRender(_ctx, _push, _parent, _attrs) {
- _push(\`<div\${_ssrRenderAttrs(_mergeProps(_attrs, {
- style: (_ctx.foo) ? null : { display: "none" }
- }))}></div>\`)
- }"
- `)
- })
- test('basic', () => {
- expect(compileWithWrapper(`<div v-show="foo"/>`).code)
- .toMatchInlineSnapshot(`
- "const { ssrRenderStyle: _ssrRenderStyle, ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
- return function ssrRender(_ctx, _push, _parent, _attrs) {
- _push(\`<div\${
- _ssrRenderAttrs(_attrs)
- }><div style="\${
- _ssrRenderStyle((_ctx.foo) ? null : { display: "none" })
- }"></div></div>\`)
- }"
- `)
- })
- test('with static style', () => {
- expect(compileWithWrapper(`<div style="color:red" v-show="foo"/>`).code)
- .toMatchInlineSnapshot(`
- "const { ssrRenderStyle: _ssrRenderStyle, ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
- return function ssrRender(_ctx, _push, _parent, _attrs) {
- _push(\`<div\${
- _ssrRenderAttrs(_attrs)
- }><div style="\${
- _ssrRenderStyle([
- {"color":"red"},
- (_ctx.foo) ? null : { display: "none" }
- ])
- }"></div></div>\`)
- }"
- `)
- })
- test('with dynamic style', () => {
- expect(
- compileWithWrapper(`<div :style="{ color: 'red' }" v-show="foo"/>`).code,
- ).toMatchInlineSnapshot(`
- "const { ssrRenderStyle: _ssrRenderStyle, ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
- return function ssrRender(_ctx, _push, _parent, _attrs) {
- _push(\`<div\${
- _ssrRenderAttrs(_attrs)
- }><div style="\${
- _ssrRenderStyle([
- { color: 'red' },
- (_ctx.foo) ? null : { display: "none" }
- ])
- }"></div></div>\`)
- }"
- `)
- })
- test('with static + dynamic style', () => {
- expect(
- compileWithWrapper(
- `<div style="color:red" :style="{ fontSize: 14 }" v-show="foo"/>`,
- ).code,
- ).toMatchInlineSnapshot(`
- "const { ssrRenderStyle: _ssrRenderStyle, ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
- 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>\`)
- }"
- `)
- })
- test('with style + display', () => {
- expect(compileWithWrapper(`<div v-show="foo" style="display:flex" />`).code)
- .toMatchInlineSnapshot(`
- "const { ssrRenderStyle: _ssrRenderStyle, ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
- return function ssrRender(_ctx, _push, _parent, _attrs) {
- _push(\`<div\${
- _ssrRenderAttrs(_attrs)
- }><div style="\${
- _ssrRenderStyle([
- {"display":"flex"},
- (_ctx.foo) ? null : { display: "none" }
- ])
- }"></div></div>\`)
- }"
- `)
- })
- test('with v-bind', () => {
- expect(
- compileWithWrapper(
- `<div v-bind="baz" style="color:red" :style="{ fontSize: 14 }" v-show="foo"/>`,
- ).code,
- ).toMatchInlineSnapshot(`
- "const { mergeProps: _mergeProps } = require("vue")
- const { ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
- 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>\`)
- }"
- `)
- })
- })
|