ssrText.spec.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { compile } from '../src'
  2. import { getCompiledString } from './utils'
  3. describe('ssr: text', () => {
  4. test('static text', () => {
  5. expect(getCompiledString(`foo`)).toMatchInlineSnapshot(`"\`foo\`"`)
  6. })
  7. test('static text escape', () => {
  8. expect(getCompiledString(`<foo>`)).toMatchInlineSnapshot(
  9. `"\`<foo>\`"`
  10. )
  11. })
  12. test('nested elements with static text', () => {
  13. expect(
  14. getCompiledString(`<div><span>hello</span><span>bye</span></div>`)
  15. ).toMatchInlineSnapshot(
  16. `"\`<div><span>hello</span><span>bye</span></div>\`"`
  17. )
  18. })
  19. test('interpolation', () => {
  20. expect(compile(`foo {{ bar }} baz`).code).toMatchInlineSnapshot(`
  21. "const { ssrInterpolate: _ssrInterpolate } = require(\\"@vue/server-renderer\\")
  22. return function ssrRender(_ctx, _push, _parent) {
  23. _push(\`foo \${_ssrInterpolate(_ctx.bar)} baz\`)
  24. }"
  25. `)
  26. })
  27. test('nested elements with interpolation', () => {
  28. expect(
  29. compile(`<div><span>{{ foo }} bar</span><span>baz {{ qux }}</span></div>`)
  30. .code
  31. ).toMatchInlineSnapshot(`
  32. "const { ssrInterpolate: _ssrInterpolate } = require(\\"@vue/server-renderer\\")
  33. return function ssrRender(_ctx, _push, _parent) {
  34. _push(\`<div><span>\${
  35. _ssrInterpolate(_ctx.foo)
  36. } bar</span><span>baz \${
  37. _ssrInterpolate(_ctx.qux)
  38. }</span></div>\`)
  39. }"
  40. `)
  41. })
  42. })