ssrInterpolate.spec.ts 671 B

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * @jest-environment node
  3. */
  4. import { ssrInterpolate } from '../src/helpers/ssrInterpolate'
  5. import { escapeHtml } from '@vue/shared'
  6. test('ssr: interpolate', () => {
  7. expect(ssrInterpolate(0)).toBe(`0`)
  8. expect(ssrInterpolate(`foo`)).toBe(`foo`)
  9. expect(ssrInterpolate(`<div>`)).toBe(`&lt;div&gt;`)
  10. // should escape interpolated values
  11. expect(ssrInterpolate([1, 2, 3])).toBe(
  12. escapeHtml(JSON.stringify([1, 2, 3], null, 2))
  13. )
  14. expect(
  15. ssrInterpolate({
  16. foo: 1,
  17. bar: `<div>`
  18. })
  19. ).toBe(
  20. escapeHtml(
  21. JSON.stringify(
  22. {
  23. foo: 1,
  24. bar: `<div>`
  25. },
  26. null,
  27. 2
  28. )
  29. )
  30. )
  31. })