mirror of https://github.com/vuejs/core.git
86 lines
2.5 KiB
TypeScript
86 lines
2.5 KiB
TypeScript
import { compile } from '../src'
|
|
|
|
describe('ssr: attrs fallthrough', () => {
|
|
test('basic', () => {
|
|
expect(compile(`<div/>`).code).toMatchInlineSnapshot(`
|
|
"const { ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
|
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
_push(\`<div\${_ssrRenderAttrs(_attrs)}></div>\`)
|
|
}"
|
|
`)
|
|
})
|
|
|
|
test('with comments', () => {
|
|
expect(compile(`<!--!--><div/>`).code).toMatchInlineSnapshot(`
|
|
"const { ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
|
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
_push(\`<!--[--><!--!--><div\${_ssrRenderAttrs(_attrs)}></div><!--]-->\`)
|
|
}"
|
|
`)
|
|
})
|
|
|
|
// #5140
|
|
test('should not inject to non-single-root if branches', () => {
|
|
expect(compile(`<div v-if="true"/><div/>`).code).toMatchInlineSnapshot(`
|
|
"
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
_push(\`<!--[-->\`)
|
|
if (true) {
|
|
_push(\`<div></div>\`)
|
|
} else {
|
|
_push(\`<!---->\`)
|
|
}
|
|
_push(\`<div></div><!--]-->\`)
|
|
}"
|
|
`)
|
|
})
|
|
|
|
test('fallthrough component content (root with comments)', () => {
|
|
expect(compile(`<!--root--><transition><div/></transition>`).code)
|
|
.toMatchInlineSnapshot(`
|
|
"const { ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
|
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
_push(\`<!--[--><!--root--><div\${_ssrRenderAttrs(_attrs)}></div><!--]-->\`)
|
|
}"
|
|
`)
|
|
})
|
|
|
|
//#8072
|
|
test(`fallthrough component content (with whitespace: 'preserve')`, () => {
|
|
expect(
|
|
compile(
|
|
`
|
|
<a v-if="to">Foo</a>
|
|
<a v-else>Bar</a>
|
|
`,
|
|
{
|
|
whitespace: 'preserve',
|
|
},
|
|
).code,
|
|
).toMatchInlineSnapshot(`
|
|
"const { ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
|
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
if (_ctx.to) {
|
|
_push(\`<a\${_ssrRenderAttrs(_attrs)}>Foo</a>\`)
|
|
} else {
|
|
_push(\`<a\${_ssrRenderAttrs(_attrs)}>Bar</a>\`)
|
|
}
|
|
}"
|
|
`)
|
|
})
|
|
|
|
test('should not inject to fallthrough component content if not root', () => {
|
|
expect(compile(`<div/><transition><div/></transition>`).code)
|
|
.toMatchInlineSnapshot(`
|
|
"
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
_push(\`<!--[--><div></div><div></div><!--]-->\`)
|
|
}"
|
|
`)
|
|
})
|
|
})
|