@@ -348,15 +348,69 @@ describe('component: slots', () => {
348
348
expect ( host . innerHTML ) . toBe ( '<div><h1>header</h1></div>' )
349
349
} )
350
350
351
+ test ( 'dynamic slot props' , async ( ) => {
352
+ let props : any
353
+
354
+ const bindObj = ref < Record < string , any > > ( { foo : 1 , baz : 'qux' } )
355
+ const Comp = defineComponent ( ( ) =>
356
+ createSlot ( 'default' , [ ( ) => bindObj . value ] ) ,
357
+ )
358
+ define ( ( ) =>
359
+ createComponent (
360
+ Comp ,
361
+ { } ,
362
+ { default : _props => ( ( props = _props ) , [ ] ) } ,
363
+ ) ,
364
+ ) . render ( )
365
+
366
+ expect ( props ) . toEqual ( { foo : 1 , baz : 'qux' } )
367
+
368
+ bindObj . value . foo = 2
369
+ await nextTick ( )
370
+ expect ( props ) . toEqual ( { foo : 2 , baz : 'qux' } )
371
+
372
+ delete bindObj . value . baz
373
+ await nextTick ( )
374
+ expect ( props ) . toEqual ( { foo : 2 } )
375
+ } )
376
+
377
+ test ( 'dynamic slot props with static slot props' , async ( ) => {
378
+ let props : any
379
+
380
+ const foo = ref ( 0 )
381
+ const bindObj = ref < Record < string , any > > ( { foo : 100 , baz : 'qux' } )
382
+ const Comp = defineComponent ( ( ) =>
383
+ createSlot ( 'default' , [ { foo : ( ) => foo . value } , ( ) => bindObj . value ] ) ,
384
+ )
385
+ define ( ( ) =>
386
+ createComponent (
387
+ Comp ,
388
+ { } ,
389
+ { default : _props => ( ( props = _props ) , [ ] ) } ,
390
+ ) ,
391
+ ) . render ( )
392
+
393
+ expect ( props ) . toEqual ( { foo : 100 , baz : 'qux' } )
394
+
395
+ foo . value = 2
396
+ await nextTick ( )
397
+ expect ( props ) . toEqual ( { foo : 100 , baz : 'qux' } )
398
+
399
+ delete bindObj . value . foo
400
+ await nextTick ( )
401
+ expect ( props ) . toEqual ( { foo : 2 , baz : 'qux' } )
402
+ } )
403
+
351
404
test ( 'slot class binding should be merged' , async ( ) => {
352
405
let props : any
353
406
354
- const enable = ref ( true )
407
+ const className = ref ( 'foo' )
408
+ const classObj = ref ( { bar : true } )
355
409
const Comp = defineComponent ( ( ) =>
356
410
createSlot ( 'default' , [
357
- { class : ( ) => 'foo' } ,
411
+ { class : ( ) => className . value } ,
358
412
( ) => ( { class : [ 'baz' , 'qux' ] } ) ,
359
- { class : ( ) => ( { bar : enable . value } ) } ,
413
+ { class : ( ) => classObj . value } ,
360
414
] ) ,
361
415
)
362
416
define ( ( ) =>
@@ -368,9 +422,51 @@ describe('component: slots', () => {
368
422
) . render ( )
369
423
370
424
expect ( props ) . toEqual ( { class : 'foo baz qux bar' } )
371
- enable . value = false
425
+
426
+ classObj . value . bar = false
372
427
await nextTick ( )
373
428
expect ( props ) . toEqual ( { class : 'foo baz qux' } )
429
+
430
+ className . value = ''
431
+ await nextTick ( )
432
+ expect ( props ) . toEqual ( { class : 'baz qux' } )
433
+ } )
434
+
435
+ test ( 'slot style binding should be merged' , async ( ) => {
436
+ let props : any
437
+
438
+ const style = ref < any > ( { fontSize : '12px' } )
439
+ const Comp = defineComponent ( ( ) =>
440
+ createSlot ( 'default' , [
441
+ { style : ( ) => style . value } ,
442
+ ( ) => ( { style : { width : '100px' , color : 'blue' } } ) ,
443
+ { style : ( ) => 'color: red' } ,
444
+ ] ) ,
445
+ )
446
+ define ( ( ) =>
447
+ createComponent (
448
+ Comp ,
449
+ { } ,
450
+ { default : _props => ( ( props = _props ) , [ ] ) } ,
451
+ ) ,
452
+ ) . render ( )
453
+
454
+ expect ( props ) . toEqual ( {
455
+ style : {
456
+ fontSize : '12px' ,
457
+ width : '100px' ,
458
+ color : 'red' ,
459
+ } ,
460
+ } )
461
+
462
+ style . value = null
463
+ await nextTick ( )
464
+ expect ( props ) . toEqual ( {
465
+ style : {
466
+ width : '100px' ,
467
+ color : 'red' ,
468
+ } ,
469
+ } )
374
470
} )
375
471
376
472
test ( 'dynamic slot should be render correctly with binds' , async ( ) => {
0 commit comments