vue3-yuanma/packages/server-renderer/__tests__/ssrUtils.spec.ts

39 lines
934 B
TypeScript
Raw Normal View History

import { escapeHtml, interpolate } from '../src'
test('ssr: escapeHTML', () => {
expect(escapeHtml(`foo`)).toBe(`foo`)
expect(escapeHtml(true)).toBe(`true`)
expect(escapeHtml(false)).toBe(`false`)
expect(escapeHtml(`a && b`)).toBe(`a && b`)
expect(escapeHtml(`"foo"`)).toBe(`"foo"`)
expect(escapeHtml(`'bar'`)).toBe(`'bar'`)
expect(escapeHtml(`<div>`)).toBe(`&lt;div&gt;`)
})
test('ssr: interpolate', () => {
expect(interpolate(0)).toBe(`0`)
expect(interpolate(`foo`)).toBe(`foo`)
expect(interpolate(`<div>`)).toBe(`&lt;div&gt;`)
// should escape interpolated values
expect(interpolate([1, 2, 3])).toBe(
escapeHtml(JSON.stringify([1, 2, 3], null, 2))
)
expect(
interpolate({
foo: 1,
bar: `<div>`
})
).toBe(
escapeHtml(
JSON.stringify(
{
foo: 1,
bar: `<div>`
},
null,
2
)
)
)
})