import { compile } from '../src'
describe('ssr: v-if', () => {
test('basic', () => {
expect(compile(`
`).code).toMatchInlineSnapshot(`
"
return function ssrRender(_ctx, _push, _parent) {
if (_ctx.foo) {
_push(\`\`)
} else {
_push(\`\`)
}
}"
`)
})
test('with nested content', () => {
expect(compile(`hellook
`).code)
.toMatchInlineSnapshot(`
"
return function ssrRender(_ctx, _push, _parent) {
if (_ctx.foo) {
_push(\`hellook
\`)
} else {
_push(\`\`)
}
}"
`)
})
test('v-if + v-else', () => {
expect(compile(``).code)
.toMatchInlineSnapshot(`
"
return function ssrRender(_ctx, _push, _parent) {
if (_ctx.foo) {
_push(\`\`)
} else {
_push(\`\`)
}
}"
`)
})
test('v-if + v-else-if', () => {
expect(compile(``).code)
.toMatchInlineSnapshot(`
"
return function ssrRender(_ctx, _push, _parent) {
if (_ctx.foo) {
_push(\`\`)
} else if (_ctx.bar) {
_push(\`\`)
} else {
_push(\`\`)
}
}"
`)
})
test('v-if + v-else-if + v-else', () => {
expect(compile(``).code)
.toMatchInlineSnapshot(`
"
return function ssrRender(_ctx, _push, _parent) {
if (_ctx.foo) {
_push(\`\`)
} else if (_ctx.bar) {
_push(\`\`)
} else {
_push(\`\`)
}
}"
`)
})
test(' (text)', () => {
expect(compile(`hello`).code)
.toMatchInlineSnapshot(`
"
return function ssrRender(_ctx, _push, _parent) {
if (_ctx.foo) {
_push(\`hello\`)
} else {
_push(\`\`)
}
}"
`)
})
test(' (single element)', () => {
// single element should not wrap with fragment
expect(compile(`hi
`).code)
.toMatchInlineSnapshot(`
"
return function ssrRender(_ctx, _push, _parent) {
if (_ctx.foo) {
_push(\`hi
\`)
} else {
_push(\`\`)
}
}"
`)
})
test(' (multiple element)', () => {
expect(
compile(`hi
ho
`).code
).toMatchInlineSnapshot(`
"
return function ssrRender(_ctx, _push, _parent) {
if (_ctx.foo) {
_push(\`hi
ho
\`)
} else {
_push(\`\`)
}
}"
`)
})
test(' (with v-for inside)', () => {
// TODO should not contain nested fragments
})
test(' + normal v-else', () => {
expect(
compile(
`hi
ho
`
).code
).toMatchInlineSnapshot(`
"
return function ssrRender(_ctx, _push, _parent) {
if (_ctx.foo) {
_push(\`hi
ho
\`)
} else {
_push(\`\`)
}
}"
`)
})
})