ssrVShow.spec.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 style=\\"\${_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. return function ssrRender(_ctx, _push, _parent) {
  16. _push(\`<div style=\\"\${_ssrRenderStyle([
  17. {\\"color\\":\\"red\\"},
  18. (_ctx.foo) ? null : { display: \\"none\\" }
  19. ])}\\"></div>\`)
  20. }"
  21. `)
  22. })
  23. test('with dynamic style', () => {
  24. expect(compile(`<div :style="{ color: 'red' }" v-show="foo"/>`).code)
  25. .toMatchInlineSnapshot(`
  26. "const { ssrRenderStyle: _ssrRenderStyle } = require(\\"@vue/server-renderer\\")
  27. return function ssrRender(_ctx, _push, _parent) {
  28. _push(\`<div style=\\"\${_ssrRenderStyle([
  29. { color: 'red' },
  30. (_ctx.foo) ? null : { display: \\"none\\" }
  31. ])}\\"></div>\`)
  32. }"
  33. `)
  34. })
  35. test('with static + dynamic style', () => {
  36. expect(
  37. compile(`<div style="color:red" :style="{ fontSize: 14 }" v-show="foo"/>`)
  38. .code
  39. ).toMatchInlineSnapshot(`
  40. "const { ssrRenderStyle: _ssrRenderStyle } = require(\\"@vue/server-renderer\\")
  41. return function ssrRender(_ctx, _push, _parent) {
  42. _push(\`<div style=\\"\${_ssrRenderStyle([
  43. {\\"color\\":\\"red\\"},
  44. { fontSize: 14 },
  45. (_ctx.foo) ? null : { display: \\"none\\" }
  46. ])}\\"></div>\`)
  47. }"
  48. `)
  49. })
  50. test('with v-bind', () => {
  51. expect(
  52. compile(
  53. `<div v-bind="baz" style="color:red" :style="{ fontSize: 14 }" v-show="foo"/>`
  54. ).code
  55. ).toMatchInlineSnapshot(`
  56. "const { mergeProps: _mergeProps } = require(\\"vue\\")
  57. const { ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")
  58. return function ssrRender(_ctx, _push, _parent) {
  59. _push(\`<div\${_ssrRenderAttrs(_mergeProps(_ctx.baz, {
  60. style: [
  61. {\\"color\\":\\"red\\"},
  62. { fontSize: 14 },
  63. (_ctx.foo) ? null : { display: \\"none\\" }
  64. ]
  65. }))}></div>\`)
  66. }"
  67. `)
  68. })
  69. })