Skip to content

Commit c749af6

Browse files
Doctor-wusxzz
authored andcommitted
test(runtime-vapor): add test case
1 parent 5f92ff8 commit c749af6

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,
@@ -325,6 +326,47 @@ describe('component: slots', () => {
325326
expect(instance.slots).not.toHaveProperty('1')
326327
})
327328

329+
test('dynamicSlots should not cover high weight static slots', async () => {
330+
const dynamicFlag = ref(true)
331+
332+
let instance: ComponentInternalInstance
333+
const { component: Child } = define({
334+
render() {
335+
instance = getCurrentInstance()!
336+
return [createSlot('default'), createSlot('others')]
337+
},
338+
})
339+
340+
const { render, html } = define({
341+
render() {
342+
return createComponent(Child, {}, [
343+
() =>
344+
dynamicFlag.value
345+
? { name: 'default', fn: () => template('dynamic default')() }
346+
: { name: 'others', fn: () => template('ohters')() },
347+
{
348+
default: () => template('default')(),
349+
},
350+
])
351+
},
352+
})
353+
354+
render()
355+
356+
expect(html()).toBe('default<!--slot--><!--slot-->')
357+
358+
dynamicFlag.value = false
359+
await nextTick()
360+
361+
expect(html()).toBe('default<!--slot-->others<!--slot-->')
362+
expect(instance!.slots).haveOwnProperty('others')
363+
364+
dynamicFlag.value = true
365+
await nextTick()
366+
expect(html()).toBe('default<!--slot--><!--slot-->')
367+
expect(instance!.slots).not.haveOwnProperty('others')
368+
})
369+
328370
test.todo('should respect $stable flag', async () => {
329371
// TODO: $stable flag?
330372
})

0 commit comments

Comments
 (0)