Skip to content

Commit 80a54dd

Browse files
committed
test(runtime-vapor): add test case
1 parent 97f0b3b commit 80a54dd

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

packages/runtime-vapor/__tests__/componentSlots.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// NOTE: This test is implemented based on the case of `runtime-core/__test__/componentSlots.spec.ts`.
22

33
import {
4+
type ComponentInternalInstance,
45
createComponent,
56
createForSlots,
67
createSlot,
@@ -291,6 +292,47 @@ describe('component: slots', () => {
291292
expect(instance.slots).not.toHaveProperty('1')
292293
})
293294

295+
test('dynamicSlots should not cover high weight static slots', async () => {
296+
const dynamicFlag = ref(true)
297+
298+
let instance: ComponentInternalInstance
299+
const { component: Child } = define({
300+
render() {
301+
instance = getCurrentInstance()!
302+
return [createSlot('default'), createSlot('others')]
303+
},
304+
})
305+
306+
const { render, html } = define({
307+
render() {
308+
return createComponent(Child, {}, [
309+
() =>
310+
dynamicFlag.value
311+
? { name: 'default', fn: () => template('dynamic default')() }
312+
: { name: 'others', fn: () => template('ohters')() },
313+
{
314+
default: () => template('default')(),
315+
},
316+
])
317+
},
318+
})
319+
320+
render()
321+
322+
expect(html()).toBe('default<!--slot--><!--slot-->')
323+
324+
dynamicFlag.value = false
325+
await nextTick()
326+
327+
expect(html()).toBe('default<!--slot-->others<!--slot-->')
328+
expect(instance!.slots).haveOwnProperty('others')
329+
330+
dynamicFlag.value = true
331+
await nextTick()
332+
expect(html()).toBe('default<!--slot--><!--slot-->')
333+
expect(instance!.slots).not.haveOwnProperty('others')
334+
})
335+
294336
test.todo('should respect $stable flag', async () => {
295337
// TODO: $stable flag?
296338
})

0 commit comments

Comments
 (0)