import { compile } from '../src' describe('ssr: v-for', () => { test('basic', () => { expect(compile(`
`).code).toMatchInlineSnapshot(` "const { ssrRenderList: _ssrRenderList } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent, _attrs) { _push(\`\`) _ssrRenderList(_ctx.list, (i) => { _push(\`
\`) }) _push(\`\`) }" `) }) test('nested content', () => { expect(compile(`
foobar
`).code) .toMatchInlineSnapshot(` "const { ssrRenderList: _ssrRenderList } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent, _attrs) { _push(\`\`) _ssrRenderList(_ctx.list, (i) => { _push(\`
foobar
\`) }) _push(\`\`) }" `) }) test('nested v-for', () => { expect( compile( `
` + `
{{ i }},{{ j }}
` + `
` ).code ).toMatchInlineSnapshot(` "const { ssrInterpolate: _ssrInterpolate, ssrRenderList: _ssrRenderList } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent, _attrs) { _push(\`\`) _ssrRenderList(_ctx.list, (row, i) => { _push(\`
\`) _ssrRenderList(row, (j) => { _push(\`
\${ _ssrInterpolate(i) },\${ _ssrInterpolate(j) }
\`) }) _push(\`
\`) }) _push(\`\`) }" `) }) test('template v-for (text)', () => { expect(compile(``).code) .toMatchInlineSnapshot(` "const { ssrInterpolate: _ssrInterpolate, ssrRenderList: _ssrRenderList } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent, _attrs) { _push(\`\`) _ssrRenderList(_ctx.list, (i) => { _push(\`\${_ssrInterpolate(i)}\`) }) _push(\`\`) }" `) }) test('template v-for (single element)', () => { expect( compile(``) .code ).toMatchInlineSnapshot(` "const { ssrInterpolate: _ssrInterpolate, ssrRenderList: _ssrRenderList } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent, _attrs) { _push(\`\`) _ssrRenderList(_ctx.list, (i) => { _push(\`\${_ssrInterpolate(i)}\`) }) _push(\`\`) }" `) }) test('template v-for (multi element)', () => { expect( compile( `` ).code ).toMatchInlineSnapshot(` "const { ssrInterpolate: _ssrInterpolate, ssrRenderList: _ssrRenderList } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent, _attrs) { _push(\`\`) _ssrRenderList(_ctx.list, (i) => { _push(\`\${ _ssrInterpolate(i) }\${ _ssrInterpolate(i + 1) }\`) }) _push(\`\`) }" `) }) test('render loop args should not be prefixed', () => { const { code } = compile( `
{{ foo + bar + index }}
` ) expect(code).toMatch(`_ctx.bar`) expect(code).not.toMatch(`_ctx.foo`) expect(code).not.toMatch(`_ctx.index`) expect(code).toMatchInlineSnapshot(` "const { ssrInterpolate: _ssrInterpolate, ssrRenderList: _ssrRenderList } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent, _attrs) { _push(\`\`) _ssrRenderList(_ctx.list, ({ foo }, index) => { _push(\`
\${_ssrInterpolate(foo + _ctx.bar + index)}
\`) }) _push(\`\`) }" `) }) })