escapeHtml.spec.ts 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. import { escapeHtml, escapeHtmlComment } from '../src'
  2. describe('escapeHtml', () => {
  3. test('ssr: escapeHTML', () => {
  4. expect(escapeHtml(`foo`)).toBe(`foo`)
  5. expect(escapeHtml(true)).toBe(`true`)
  6. expect(escapeHtml(false)).toBe(`false`)
  7. expect(escapeHtml(`a && b`)).toBe(`a && b`)
  8. expect(escapeHtml(`"foo"`)).toBe(`"foo"`)
  9. expect(escapeHtml(`'bar'`)).toBe(`'bar'`)
  10. expect(escapeHtml(`<div>`)).toBe(`&lt;div&gt;`)
  11. })
  12. test('ssr: escapeHTMLComment', () => {
  13. const input = '<!-- Hello --><!-- World! -->'
  14. const result = escapeHtmlComment(input)
  15. expect(result).toEqual(' Hello World! ')
  16. })
  17. test('ssr: escapeHTMLComment', () => {
  18. const input = '<!-- Comment 1 --> Hello <!--! Comment 2 --> World!'
  19. const result = escapeHtmlComment(input)
  20. expect(result).toEqual(' Comment 1 Hello ! Comment 2 World!')
  21. })
  22. test('should not affect non-comment strings', () => {
  23. const input = 'Hello World'
  24. const result = escapeHtmlComment(input)
  25. expect(result).toEqual(input)
  26. })
  27. })