@@ -10,6 +10,7 @@ import {
10
10
Fragment ,
11
11
h ,
12
12
isVNode ,
13
+ ref ,
13
14
Text ,
14
15
type VNode ,
15
16
type VNodeArrayChildren ,
@@ -422,6 +423,49 @@ describe('addProps', () => {
422
423
expect ( fragment [ 0 ] ) . toBe ( spanNode )
423
424
expect ( spanNode . props ) . toBe ( null )
424
425
} )
426
+
427
+ it ( 'addProps - 8259' , ( ) => {
428
+ let count = 0
429
+
430
+ const spanRef = ref ( )
431
+ const otherRef = ref ( )
432
+ const spanNode = h ( 'span' , { ref : spanRef , class : 'bold' , style : 'color: red' } )
433
+ const startNodes = [ spanNode ]
434
+
435
+ const nodes = addProps ( startNodes , ( ) => {
436
+ count ++
437
+
438
+ return {
439
+ ref : otherRef ,
440
+ class : 'large' ,
441
+ style : 'line-height: 1'
442
+ }
443
+ } )
444
+
445
+ expect ( count ) . toBe ( 1 )
446
+
447
+ expect ( nodes ) . toHaveLength ( 1 )
448
+
449
+ const newNode = nodes [ 0 ] as VNode
450
+ const props = newNode . props
451
+
452
+ expect ( props ?. class ) . toBe ( 'bold large' )
453
+ expect ( props ?. style . color ) . toBe ( 'red' )
454
+ expect ( props ?. style [ 'line-height' ] ) . toBe ( '1' )
455
+
456
+ const mergedRef = newNode . ref
457
+
458
+ expect ( Array . isArray ( mergedRef ) ) . toBe ( true )
459
+ expect ( mergedRef ) . toHaveLength ( 2 )
460
+
461
+ // Keep TS happy...
462
+ if ( Array . isArray ( mergedRef ) ) {
463
+ const refs = mergedRef . map ( ( { r } ) => r )
464
+
465
+ expect ( refs . includes ( spanRef ) ) . toBe ( true )
466
+ expect ( refs . includes ( otherRef ) ) . toBe ( true )
467
+ }
468
+ } )
425
469
} )
426
470
427
471
describe ( 'replaceChildren' , ( ) => {
0 commit comments