2020-02-04 06:47:06 +08:00
|
|
|
import { compile } from '../src'
|
2020-02-04 00:46:14 +08:00
|
|
|
import { getCompiledString } from './utils'
|
|
|
|
|
2020-02-04 04:51:41 +08:00
|
|
|
describe('ssr: text', () => {
|
2020-02-04 00:46:14 +08:00
|
|
|
test('static text', () => {
|
|
|
|
expect(getCompiledString(`foo`)).toMatchInlineSnapshot(`"\`foo\`"`)
|
|
|
|
})
|
|
|
|
|
|
|
|
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', () => {
|
2020-02-04 06:47:06 +08:00
|
|
|
expect(compile(`foo {{ bar }} baz`).code).toMatchInlineSnapshot(`
|
|
|
|
"const { _interpolate } = require(\\"@vue/server-renderer\\")
|
|
|
|
|
|
|
|
return function ssrRender(_ctx, _push, _parent) {
|
|
|
|
_push(\`foo \${_interpolate(_ctx.bar)} baz\`)
|
|
|
|
}"
|
|
|
|
`)
|
2020-02-04 00:46:14 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('nested elements with interpolation', () => {
|
|
|
|
expect(
|
2020-02-04 06:47:06 +08:00
|
|
|
compile(`<div><span>{{ foo }} bar</span><span>baz {{ qux }}</span></div>`)
|
|
|
|
.code
|
|
|
|
).toMatchInlineSnapshot(`
|
|
|
|
"const { _interpolate } = require(\\"@vue/server-renderer\\")
|
|
|
|
|
|
|
|
return function ssrRender(_ctx, _push, _parent) {
|
|
|
|
_push(\`<div><span>\${_interpolate(_ctx.foo)} bar</span><span>baz \${_interpolate(_ctx.qux)}</span></div>\`)
|
|
|
|
}"
|
|
|
|
`)
|
2020-02-04 00:46:14 +08:00
|
|
|
})
|
|
|
|
})
|