Skip to content

Commit 06d3691

Browse files
committed
test(compiler-vapor): add test for component v-if handling
1 parent 8b4487e commit 06d3691

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ export function render(_ctx) {
4444
}"
4545
`;
4646

47+
exports[`compiler: v-if > component v-if 1`] = `
48+
"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback, createIf as _createIf } from 'vue';
49+
50+
export function render(_ctx) {
51+
const _component_Component = _resolveComponent("Component")
52+
const n0 = _createIf(() => (_ctx.ok), () => {
53+
const n2 = _createComponentWithFallback(_component_Component, null, null, true)
54+
return n2
55+
})
56+
return n0
57+
}"
58+
`;
59+
4760
exports[`compiler: v-if > dedupe same template 1`] = `
4861
"import { createIf as _createIf, template as _template } from 'vue';
4962
const t0 = _template("<div>hello</div>")

packages/compiler-vapor/__tests__/transforms/vIf.spec.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,33 @@ describe('compiler: v-if', () => {
205205
})
206206

207207
test.todo('v-if with v-once')
208-
test.todo('component v-if')
208+
209+
test('component v-if', () => {
210+
const { code, ir, helpers } = compileWithVIf(
211+
`<Component v-if="ok"></Component>`,
212+
)
213+
expect(code).matchSnapshot()
214+
expect(helpers).contains('createIf')
215+
expect(ir.block.effect).lengthOf(0)
216+
expect(ir.block.dynamic.children[0].operation).toMatchObject({
217+
type: IRNodeTypes.IF,
218+
id: 0,
219+
condition: {
220+
type: NodeTypes.SIMPLE_EXPRESSION,
221+
content: 'ok',
222+
isStatic: false,
223+
},
224+
positive: {
225+
type: IRNodeTypes.BLOCK,
226+
dynamic: {
227+
children: [
228+
{ operation: { asset: true, tag: 'Component', type: 11 } },
229+
],
230+
},
231+
},
232+
})
233+
expect(ir.block.returns).toEqual([0])
234+
})
209235

210236
test('v-if + v-else', () => {
211237
const { code, ir, helpers } = compileWithVIf(`<div v-if="ok"/><p v-else/>`)

0 commit comments

Comments
 (0)