import { getCompiledString } from './utils' import { compile } from '../src' describe('ssr: element', () => { test('basic elements', () => { expect(getCompiledString(`
`)).toMatchInlineSnapshot( `"\`
\`"` ) expect(getCompiledString(`
`)).toMatchInlineSnapshot( `"\`
\`"` ) }) test('nested elements', () => { expect( getCompiledString(`
`) ).toMatchInlineSnapshot(`"\`
\`"`) }) test('void element', () => { expect(getCompiledString(``)).toMatchInlineSnapshot(`"\`\`"`) }) describe('children override', () => { test('v-html', () => { expect(getCompiledString(`
`)).toMatchInlineSnapshot(` "\`
\${ _ctx.foo }
\`" `) }) test('v-text', () => { expect(getCompiledString(`
`)).toMatchInlineSnapshot(` "\`
\${ _ssrInterpolate(_ctx.foo) }
\`" `) }) test('\`" `) }) test('\`"`) }) test('`).code) .toMatchInlineSnapshot(` "const { mergeProps: _mergeProps } = require(\\"vue\\") const { ssrRenderAttrs: _ssrRenderAttrs, ssrInterpolate: _ssrInterpolate } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent, _attrs) { let _temp0 _push(\`\${ _ssrInterpolate((\\"value\\" in _temp0) ? _temp0.value : \\"fallback\\") }\`) }" `) }) test('multiple _ssrInterpolate at parent and child import dependency once', () => { expect( compile(`
{{ hello }}
`).code ).toMatchInlineSnapshot(` "const { ssrRenderAttrs: _ssrRenderAttrs, ssrInterpolate: _ssrInterpolate } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent, _attrs) { let _temp0 _push(\`\${ _ssrInterpolate(_ctx.hello) }\${ _ssrInterpolate((\\"value\\" in _temp0) ? _temp0.value : \\"\\") }
\`) }" `) }) test('should pass tag to custom elements w/ dynamic v-bind', () => { expect( compile(``, { isCustomElement: () => true }).code ).toMatchInlineSnapshot(` "const { mergeProps: _mergeProps } = require(\\"vue\\") const { ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent, _attrs) { _push(\`\`) }" `) }) }) describe('attrs', () => { test('static attrs', () => { expect( getCompiledString(`
`) ).toMatchInlineSnapshot(`"\`
\`"`) }) test('ignore static key/ref', () => { expect( getCompiledString(`
`) ).toMatchInlineSnapshot(`"\`
\`"`) }) test('ignore v-bind key/ref', () => { expect( getCompiledString(`
`) ).toMatchInlineSnapshot(`"\`
\`"`) }) test('v-bind:class', () => { expect(getCompiledString(`
`)) .toMatchInlineSnapshot(` "\`
\`" `) }) test('static class + v-bind:class', () => { expect(getCompiledString(`
`)) .toMatchInlineSnapshot(` "\`
\`" `) }) test('v-bind:class + static class', () => { expect(getCompiledString(`
`)) .toMatchInlineSnapshot(` "\`
\`" `) }) test('v-bind:style', () => { expect(getCompiledString(`
`)) .toMatchInlineSnapshot(` "\`
\`" `) }) test('static style + v-bind:style', () => { expect(getCompiledString(`
`)) .toMatchInlineSnapshot(` "\`
\`" `) }) test('v-bind:arg (boolean)', () => { expect(getCompiledString(``)) .toMatchInlineSnapshot(` "\`\`" `) }) test('v-bind:arg (non-boolean)', () => { expect(getCompiledString(`
`)) .toMatchInlineSnapshot(` "\`
\`" `) }) test('v-bind:[arg]', () => { expect(getCompiledString(`
`)) .toMatchInlineSnapshot(` "\`
\`" `) expect(getCompiledString(`
`)) .toMatchInlineSnapshot(` "\`\`" `) expect(getCompiledString(`
`)) .toMatchInlineSnapshot(` "\`\`" `) }) test('v-bind="obj"', () => { expect(getCompiledString(`
`)) .toMatchInlineSnapshot(` "\`\`" `) expect(getCompiledString(`
`)) .toMatchInlineSnapshot(` "\`\`" `) expect(getCompiledString(`
`)) .toMatchInlineSnapshot(` "\`\`" `) // dynamic key + v-bind="object" expect(getCompiledString(`
`)) .toMatchInlineSnapshot(` "\`\`" `) // should merge class and :class expect(getCompiledString(`
`)) .toMatchInlineSnapshot(` "\`\`" `) // should merge style and :style expect( getCompiledString( `
` ) ).toMatchInlineSnapshot(` "\`\`" `) }) test('should ignore v-on', () => { expect( getCompiledString(`
`) ).toMatchInlineSnapshot(`"\`
\`"`) expect( getCompiledString(`
`) ).toMatchInlineSnapshot(`"\`
\`"`) expect(getCompiledString(`
`)) .toMatchInlineSnapshot(` "\`
\`" `) }) }) })