2
0

ssrElement.spec.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { getCompiledString } from './utils'
  2. describe('ssr: element', () => {
  3. test('basic elements', () => {
  4. expect(getCompiledString(`<div></div>`)).toMatchInlineSnapshot(
  5. `"\`<div></div>\`"`
  6. )
  7. expect(getCompiledString(`<div/>`)).toMatchInlineSnapshot(
  8. `"\`<div></div>\`"`
  9. )
  10. })
  11. test('nested elements', () => {
  12. expect(
  13. getCompiledString(`<div><span></span><span></span></div>`)
  14. ).toMatchInlineSnapshot(`"\`<div><span></span><span></span></div>\`"`)
  15. })
  16. test('void element', () => {
  17. expect(getCompiledString(`<input>`)).toMatchInlineSnapshot(`"\`<input>\`"`)
  18. })
  19. describe('children override', () => {
  20. test('v-html', () => {
  21. expect(getCompiledString(`<div v-html="foo"/>`)).toMatchInlineSnapshot(
  22. `"\`<div>\${_ctx.foo}</div>\`"`
  23. )
  24. })
  25. test('v-text', () => {
  26. expect(getCompiledString(`<div v-text="foo"/>`)).toMatchInlineSnapshot(
  27. `"\`<div>\${_interpolate(_ctx.foo)}</div>\`"`
  28. )
  29. })
  30. test('<textarea> with dynamic value', () => {
  31. expect(
  32. getCompiledString(`<textarea :value="foo"/>`)
  33. ).toMatchInlineSnapshot(
  34. `"\`<textarea>\${_interpolate(_ctx.foo)}</textarea>\`"`
  35. )
  36. })
  37. test('<textarea> with static value', () => {
  38. expect(
  39. getCompiledString(`<textarea value="fo&gt;o"/>`)
  40. ).toMatchInlineSnapshot(`"\`<textarea>fo&gt;o</textarea>\`"`)
  41. })
  42. })
  43. describe('attrs', () => {
  44. test('static attrs', () => {
  45. expect(
  46. getCompiledString(`<div id="foo" class="bar"></div>`)
  47. ).toMatchInlineSnapshot(`"\`<div id=\\"foo\\" class=\\"bar\\"></div>\`"`)
  48. })
  49. test('v-bind:class', () => {
  50. expect(
  51. getCompiledString(`<div id="foo" :class="bar"></div>`)
  52. ).toMatchInlineSnapshot(
  53. `"\`<div id=\\"foo\\"\${_renderClass(_ctx.bar)}></div>\`"`
  54. )
  55. })
  56. test('v-bind:style', () => {
  57. expect(
  58. getCompiledString(`<div id="foo" :style="bar"></div>`)
  59. ).toMatchInlineSnapshot(
  60. `"\`<div id=\\"foo\\"\${_renderStyle(_ctx.bar)}></div>\`"`
  61. )
  62. })
  63. test('v-bind:key (boolean)', () => {
  64. expect(
  65. getCompiledString(`<input type="checkbox" :checked="checked">`)
  66. ).toMatchInlineSnapshot(
  67. `"\`<input type=\\"checkbox\\"\${(_ctx.checked)? \\" checked\\": \\"\\"}>\`"`
  68. )
  69. })
  70. test('v-bind:key (non-boolean)', () => {
  71. expect(
  72. getCompiledString(`<div :id="id" class="bar"></div>`)
  73. ).toMatchInlineSnapshot(
  74. `"\`<div\${_renderAttr(\\"id\\", _ctx.id)} class=\\"bar\\"></div>\`"`
  75. )
  76. })
  77. })
  78. })