| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 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><!--]-->\`)
- }"
- `)
- })
- })
|