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

34 lines
671 B
TypeScript
Raw Normal View History

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