|
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,
|
@@ -291,6 +292,47 @@ describe('component: slots', () => {
|
291 | 292 | expect(instance.slots).not.toHaveProperty('1')
|
292 | 293 | })
|
293 | 294 |
|
| 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 | + |
294 | 336 | test.todo('should respect $stable flag', async () => {
|
295 | 337 | // TODO: $stable flag?
|
296 | 338 | })
|
|
0 commit comments