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'
|
2020-01-30 04:10:45 +08:00
|
|
|
|
|
|
|
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(`<div>`)
|
2020-01-30 04:10:45 +08:00
|
|
|
// should escape interpolated values
|
2020-02-07 01:07:25 +08:00
|
|
|
expect(ssrInterpolate([1, 2, 3])).toBe(
|
2020-01-30 04:10:45 +08:00
|
|
|
escapeHtml(JSON.stringify([1, 2, 3], null, 2))
|
|
|
|
)
|
|
|
|
expect(
|
2020-02-07 01:07:25 +08:00
|
|
|
ssrInterpolate({
|
2020-01-30 04:10:45 +08:00
|
|
|
foo: 1,
|
|
|
|
bar: `<div>`
|
|
|
|
})
|
|
|
|
).toBe(
|
|
|
|
escapeHtml(
|
|
|
|
JSON.stringify(
|
|
|
|
{
|
|
|
|
foo: 1,
|
|
|
|
bar: `<div>`
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
2
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
})
|