ssrVShow.spec.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { compile } from '../src'
  2. describe('ssr: v-show', () => {
  3. test('basic', () => {
  4. expect(compile(`<div v-show="foo"/>`).code).toMatchInlineSnapshot(`
  5. "const { ssrRenderStyle: _ssrRenderStyle } = require(\\"@vue/server-renderer\\")
  6. return function ssrRender(_ctx, _push, _parent) {
  7. _push(\`<div\${_ssrRenderStyle((_ctx.foo) ? null : { display: \\"none\\" })}></div>\`)
  8. }"
  9. `)
  10. })
  11. test('with static style', () => {
  12. expect(compile(`<div style="color:red" v-show="foo"/>`).code)
  13. .toMatchInlineSnapshot(`
  14. "const { ssrRenderStyle: _ssrRenderStyle } = require(\\"@vue/server-renderer\\")
  15. const _hoisted_1 = {\\"color\\":\\"red\\"}
  16. return function ssrRender(_ctx, _push, _parent) {
  17. _push(\`<div\${_ssrRenderStyle([
  18. _hoisted_1,
  19. (_ctx.foo) ? null : { display: \\"none\\" }
  20. ])}></div>\`)
  21. }"
  22. `)
  23. })
  24. test('with dynamic style', () => {
  25. expect(compile(`<div :style="{ color: 'red' }" v-show="foo"/>`).code)
  26. .toMatchInlineSnapshot(`
  27. "const { ssrRenderStyle: _ssrRenderStyle } = require(\\"@vue/server-renderer\\")
  28. return function ssrRender(_ctx, _push, _parent) {
  29. _push(\`<div\${_ssrRenderStyle([
  30. { color: 'red' },
  31. (_ctx.foo) ? null : { display: \\"none\\" }
  32. ])}></div>\`)
  33. }"
  34. `)
  35. })
  36. test('with static + dynamic style', () => {
  37. expect(
  38. compile(`<div style="color:red" :style="{ fontSize: 14 }" v-show="foo"/>`)
  39. .code
  40. ).toMatchInlineSnapshot(`
  41. "const { ssrRenderStyle: _ssrRenderStyle } = require(\\"@vue/server-renderer\\")
  42. const _hoisted_1 = {\\"color\\":\\"red\\"}
  43. return function ssrRender(_ctx, _push, _parent) {
  44. _push(\`<div\${_ssrRenderStyle([
  45. _hoisted_1,
  46. { fontSize: 14 },
  47. (_ctx.foo) ? null : { display: \\"none\\" }
  48. ])}></div>\`)
  49. }"
  50. `)
  51. })
  52. test('with v-bind', () => {
  53. expect(
  54. compile(
  55. `<div v-bind="baz" style="color:red" :style="{ fontSize: 14 }" v-show="foo"/>`
  56. ).code
  57. ).toMatchInlineSnapshot(`
  58. "const { mergeProps: _mergeProps } = require(\\"vue\\")
  59. const { ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")
  60. const _hoisted_1 = {\\"color\\":\\"red\\"}
  61. return function ssrRender(_ctx, _push, _parent) {
  62. _push(\`<div\${_ssrRenderAttrs(_mergeProps(_ctx.baz, {
  63. style: [
  64. _hoisted_1,
  65. { fontSize: 14 },
  66. (_ctx.foo) ? null : { display: \\"none\\" }
  67. ]
  68. }))}></div>\`)
  69. }"
  70. `)
  71. })
  72. })