|
1 | 1 | // NOTE: This test is implemented based on the case of `runtime-core/__test__/componentSlots.spec.ts`.
|
2 | 2 |
|
3 | 3 | import {
|
| 4 | + type ComponentInternalInstance, |
4 | 5 | createComponent,
|
5 | 6 | createForSlots,
|
6 | 7 | createSlot,
|
@@ -325,6 +326,47 @@ describe('component: slots', () => {
|
325 | 326 | expect(instance.slots).not.toHaveProperty('1')
|
326 | 327 | })
|
327 | 328 |
|
| 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 | + |
328 | 370 | test.todo('should respect $stable flag', async () => {
|
329 | 371 | // TODO: $stable flag?
|
330 | 372 | })
|
|
0 commit comments