56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { compile } from '../src'
|
|
import { getCompiledString } from './utils'
|
|
|
|
describe('ssr: text', () => {
|
|
test('static text', () => {
|
|
expect(getCompiledString(`foo`)).toMatchInlineSnapshot(`"\`foo\`"`)
|
|
})
|
|
|
|
test('comments', () => {
|
|
expect(getCompiledString(`<!--bar-->`)).toMatchInlineSnapshot(
|
|
`"\`<!--bar-->\`"`
|
|
)
|
|
})
|
|
|
|
test('static text escape', () => {
|
|
expect(getCompiledString(`<foo>`)).toMatchInlineSnapshot(
|
|
`"\`<foo>\`"`
|
|
)
|
|
})
|
|
|
|
test('nested elements with static text', () => {
|
|
expect(
|
|
getCompiledString(`<div><span>hello</span><span>bye</span></div>`)
|
|
).toMatchInlineSnapshot(
|
|
`"\`<div><span>hello</span><span>bye</span></div>\`"`
|
|
)
|
|
})
|
|
|
|
test('interpolation', () => {
|
|
expect(compile(`foo {{ bar }} baz`).code).toMatchInlineSnapshot(`
|
|
"const { ssrInterpolate: _ssrInterpolate } = require(\\"@vue/server-renderer\\")
|
|
|
|
return function ssrRender(_ctx, _push, _parent) {
|
|
_push(\`foo \${_ssrInterpolate(_ctx.bar)} baz\`)
|
|
}"
|
|
`)
|
|
})
|
|
|
|
test('nested elements with interpolation', () => {
|
|
expect(
|
|
compile(`<div><span>{{ foo }} bar</span><span>baz {{ qux }}</span></div>`)
|
|
.code
|
|
).toMatchInlineSnapshot(`
|
|
"const { ssrInterpolate: _ssrInterpolate } = require(\\"@vue/server-renderer\\")
|
|
|
|
return function ssrRender(_ctx, _push, _parent) {
|
|
_push(\`<div><span>\${
|
|
_ssrInterpolate(_ctx.foo)
|
|
} bar</span><span>baz \${
|
|
_ssrInterpolate(_ctx.qux)
|
|
}</span></div>\`)
|
|
}"
|
|
`)
|
|
})
|
|
})
|