Skip to content

Commit 0c0a131

Browse files
committed
test: improve the test
1 parent b51c735 commit 0c0a131

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

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

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
IRNodeTypes,
23
transformChildren,
34
transformElement,
45
transformSlotOutlet,
@@ -29,17 +30,63 @@ const compileWithSlots = makeCompile({
2930

3031
describe('compiler: transform slot', () => {
3132
test('implicit default slot', () => {
32-
const { code } = compileWithSlots(`<Comp><div/></Comp>`)
33+
const { ir, code } = compileWithSlots(`<Comp><div/></Comp>`)
3334
expect(code).toMatchSnapshot()
35+
36+
expect(ir.template).toEqual(['<div></div>'])
37+
expect(ir.block.operation).toMatchObject([
38+
{
39+
type: IRNodeTypes.CREATE_COMPONENT_NODE,
40+
id: 1,
41+
tag: 'Comp',
42+
props: [[]],
43+
slots: {
44+
default: {
45+
type: IRNodeTypes.BLOCK,
46+
dynamic: {
47+
children: [{ template: 0 }],
48+
},
49+
},
50+
},
51+
},
52+
])
53+
expect(ir.block.returns).toEqual([1])
54+
expect(ir.block.dynamic).toMatchObject({
55+
children: [{ id: 1 }],
56+
})
3457
})
3558

3659
test('named slots w/ implicit default slot', () => {
37-
const { code } = compileWithSlots(
60+
const { ir, code } = compileWithSlots(
3861
`<Comp>
3962
<template #one>foo</template>bar<span/>
4063
</Comp>`,
4164
)
4265
expect(code).toMatchSnapshot()
66+
67+
expect(ir.template).toEqual(['foo', 'bar', '<span></span>'])
68+
expect(ir.block.operation).toMatchObject([
69+
{
70+
type: IRNodeTypes.CREATE_COMPONENT_NODE,
71+
id: 4,
72+
tag: 'Comp',
73+
props: [[]],
74+
slots: {
75+
one: {
76+
type: IRNodeTypes.BLOCK,
77+
dynamic: {
78+
children: [{ template: 0 }],
79+
},
80+
},
81+
default: {
82+
type: IRNodeTypes.BLOCK,
83+
dynamic: {
84+
children: [{}, { template: 1 }, { template: 2 }],
85+
},
86+
},
87+
},
88+
},
89+
])
4390
})
4491

4592
test('nested slots', () => {

0 commit comments

Comments
 (0)