import { compile } from '../src' describe('ssr: v-for', () => { test('basic', () => { expect(compile(`
`).code).toMatchInlineSnapshot(` "const { _renderList } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { _push(\`\`) _renderList(_ctx.list, (i) => { _push(\`
\`) }) _push(\`\`) }" `) }) test('nested content', () => { expect(compile(`
foobar
`).code) .toMatchInlineSnapshot(` "const { _renderList } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { _push(\`\`) _renderList(_ctx.list, (i) => { _push(\`
foobar
\`) }) _push(\`\`) }" `) }) test('nested v-for', () => { expect( compile( `
` + `
{{ i }},{{ j }}
` + `
` ).code ).toMatchInlineSnapshot(` "const { _interpolate, _renderList } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { _push(\`\`) _renderList(_ctx.list, (row, i) => { _push(\`
\`) _renderList(row, (j) => { _push(\`
\${_interpolate(i)},\${_interpolate(j)}
\`) }) _push(\`
\`) }) _push(\`\`) }" `) }) test('template v-for (text)', () => { expect(compile(``).code) .toMatchInlineSnapshot(` "const { _interpolate, _renderList } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { _push(\`\`) _renderList(_ctx.list, (i) => { _push(\`\${_interpolate(i)}\`) }) _push(\`\`) }" `) }) test('template v-for (single element)', () => { expect( compile(``) .code ).toMatchInlineSnapshot(` "const { _interpolate, _renderList } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { _push(\`\`) _renderList(_ctx.list, (i) => { _push(\`\${_interpolate(i)}\`) }) _push(\`\`) }" `) }) test('template v-for (multi element)', () => { expect( compile( `` ).code ).toMatchInlineSnapshot(` "const { _interpolate, _renderList } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { _push(\`\`) _renderList(_ctx.list, (i) => { _push(\`\${_interpolate(i)}\${_interpolate(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 { _interpolate, _renderList } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { _push(\`\`) _renderList(_ctx.list, ({ foo }, index) => { _push(\`
\${_interpolate(foo + _ctx.bar + index)}
\`) }) _push(\`\`) }" `) }) })