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

30 lines
615 B
TypeScript
Raw Normal View History

import { interpolate } from '../src/helpers/interpolate'
2020-02-04 06:47:06 +08:00
import { escapeHtml } from '@vue/shared'
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
)
)
)
})