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

30 lines
601 B
TypeScript
Raw Normal View History

2020-02-04 06:47:06 +08:00
import { _interpolate } from '../src'
import { escapeHtml } from '@vue/shared'
test('ssr: interpolate', () => {
2020-02-04 06:47:06 +08:00
expect(_interpolate(0)).toBe(`0`)
expect(_interpolate(`foo`)).toBe(`foo`)
expect(_interpolate(`<div>`)).toBe(`&lt;div&gt;`)
// should escape interpolated values
2020-02-04 06:47:06 +08:00
expect(_interpolate([1, 2, 3])).toBe(
escapeHtml(JSON.stringify([1, 2, 3], null, 2))
)
expect(
2020-02-04 06:47:06 +08:00
_interpolate({
foo: 1,
bar: `<div>`
})
).toBe(
escapeHtml(
JSON.stringify(
{
foo: 1,
bar: `<div>`
},
null,
2
)
)
)
})