@@ -224,10 +224,12 @@ describe('addProps', () => {
224
224
expect ( child . type ) . toBe ( 'div' )
225
225
expect ( child . props ?. class ) . toBe ( 'red' )
226
226
227
- // TODO
228
- // expect(startNodes.length).toBe(1)
229
- // expect(startNodes[0]).toBe(startNode)
230
- // expect(startNode.props).toBe(null)
227
+ expect ( startNodes . length ) . toBe ( 1 )
228
+ expect ( startNodes [ 0 ] ) . toBe ( fragNode )
229
+ expect ( fragNode . props ) . toBe ( null )
230
+ expect ( fragNode . children ?. length ) . toBe ( 1 )
231
+ expect ( ( fragNode . children as VNodeArrayChildren ) [ 0 ] ) . toBe ( divNode )
232
+ expect ( divNode . props ) . toBe ( null )
231
233
} )
232
234
233
235
it ( 'addProps - 3de9' , ( ) => {
@@ -380,14 +382,9 @@ describe('addProps', () => {
380
382
compareChildren ( nullNodes , referenceNodes )
381
383
compareChildren ( emptyNodes , referenceNodes )
382
384
383
- expect ( undefinedNodes [ 0 ] ) . toBe ( startNodes [ 0 ] )
384
- expect ( undefinedNodes [ 1 ] ) . toBe ( startNodes [ 1 ] )
385
-
386
- expect ( nullNodes [ 0 ] ) . toBe ( startNodes [ 0 ] )
387
- expect ( nullNodes [ 1 ] ) . toBe ( startNodes [ 1 ] )
388
-
389
- expect ( emptyNodes [ 0 ] ) . toBe ( startNodes [ 0 ] )
390
- expect ( emptyNodes [ 1 ] ) . toBe ( startNodes [ 1 ] )
385
+ expect ( undefinedNodes ) . toBe ( startNodes )
386
+ expect ( nullNodes ) . toBe ( startNodes )
387
+ expect ( emptyNodes ) . toBe ( startNodes )
391
388
} )
392
389
393
390
it ( 'addProps - a934' , ( ) => {
@@ -428,6 +425,33 @@ describe('addProps', () => {
428
425
expect ( ( nodes [ 0 ] as VNode ) . props ?. class ) . toBe ( undefined )
429
426
expect ( ( nodes [ 1 ] as VNode ) . props ?. class ) . toBe ( 'red' )
430
427
} )
428
+
429
+ it ( 'addProps - 510f' , ( ) => {
430
+ let count = 0
431
+
432
+ const spanNode = h ( 'span' )
433
+ const fragment = [ spanNode ]
434
+ const startNodes = [ h ( 'div' ) , fragment ]
435
+
436
+ const nodes = addProps ( startNodes , ( vnode ) => {
437
+ count ++
438
+
439
+ if ( vnode . type === 'div' ) {
440
+ return {
441
+ class : 'red'
442
+ }
443
+ }
444
+ } )
445
+
446
+ expect ( count ) . toBe ( 2 )
447
+
448
+ expect ( nodes . length ) . toBe ( 2 )
449
+ expect ( ( nodes [ 0 ] as VNode ) . props ?. class ) . toBe ( 'red' )
450
+ expect ( nodes [ 1 ] ) . toBe ( fragment )
451
+ expect ( fragment . length ) . toBe ( 1 )
452
+ expect ( fragment [ 0 ] ) . toBe ( spanNode )
453
+ expect ( spanNode . props ) . toBe ( null )
454
+ } )
431
455
} )
432
456
433
457
describe ( 'replaceChildren' , ( ) => {
@@ -450,9 +474,9 @@ describe('replaceChildren', () => {
450
474
expect ( count ) . toBe ( 1 )
451
475
expect ( Array . isArray ( nodes ) ) . toBe ( true )
452
476
expect ( nodes ) . toHaveLength ( 1 )
477
+ expect ( nodes ) . toBe ( startNodes )
453
478
454
479
compareChildren ( startNodes , [ h ( 'div' ) ] )
455
- compareChildren ( nodes , [ h ( 'div' ) ] )
456
480
} )
457
481
458
482
it ( 'replaceChildren - 7c8a' , ( ) => {
@@ -476,6 +500,7 @@ describe('replaceChildren', () => {
476
500
expect ( nodes ) . toHaveLength ( 0 )
477
501
478
502
compareChildren ( startNodes , [ h ( 'div' ) ] )
503
+ expect ( startNodes [ 0 ] ) . toBe ( startNode )
479
504
} )
480
505
481
506
it ( 'replaceChildren - 1d16' , ( ) => {
@@ -601,6 +626,37 @@ describe('replaceChildren', () => {
601
626
compareChildren ( startNodes , [ h ( 'div' ) , 'Text' , [ h ( 'span' ) , 'More text' ] ] )
602
627
compareChildren ( nodes , [ h ( 'div' ) , '(Text)' , [ h ( 'span' ) , '(More text)' ] ] )
603
628
} )
629
+
630
+ it ( 'replaceChildren - e076' , ( ) => {
631
+ let count = 0
632
+
633
+ const startNodes = [ 'Text' ]
634
+
635
+ const nodes = replaceChildren ( startNodes , ( ) => {
636
+ count ++
637
+ } )
638
+
639
+ expect ( count ) . toBe ( 1 )
640
+ expect ( Array . isArray ( nodes ) ) . toBe ( true )
641
+ expect ( nodes ) . toHaveLength ( 1 )
642
+ expect ( isVNode ( nodes [ 0 ] ) ) . toBe ( true )
643
+
644
+ expect ( startNodes ) . toHaveLength ( 1 )
645
+ expect ( startNodes [ 0 ] ) . toBe ( 'Text' )
646
+
647
+ // Do the same thing with a text VNode
648
+ const startVNodes = [ createTextVNode ( 'Text' ) ]
649
+
650
+ count = 0
651
+
652
+ const nodesOut = replaceChildren ( startVNodes , ( ) => {
653
+ count ++
654
+ } )
655
+
656
+ expect ( count ) . toBe ( 1 )
657
+ expect ( nodesOut ) . toBe ( startVNodes )
658
+ expect ( nodesOut ) . toHaveLength ( 1 )
659
+ } )
604
660
} )
605
661
606
662
describe ( 'betweenChildren' , ( ) => {
@@ -615,17 +671,11 @@ describe('betweenChildren', () => {
615
671
} )
616
672
617
673
expect ( count ) . toBe ( 0 )
618
- expect ( Array . isArray ( nodes ) ) . toBe ( true )
619
- expect ( nodes . length ) . toBe ( 1 )
620
-
621
- const node = nodes [ 0 ] as VNode
674
+ expect ( nodes ) . toBe ( startNodes )
622
675
623
- expect ( isElement ( node ) ) . toBe ( true )
624
- expect ( node . type ) . toBe ( 'div' )
625
- expect ( node . props ) . toBe ( null )
626
-
627
- expect ( startNodes . length ) . toBe ( 1 )
676
+ expect ( startNodes ) . toHaveLength ( 1 )
628
677
expect ( startNodes [ 0 ] ) . toBe ( startNode )
678
+ expect ( startNode . type ) . toBe ( 'div' )
629
679
expect ( startNode . props ) . toBe ( null )
630
680
} )
631
681
@@ -649,10 +699,8 @@ describe('betweenChildren', () => {
649
699
} )
650
700
651
701
expect ( count ) . toBe ( 1 )
652
- expect ( Array . isArray ( nodes ) ) . toBe ( true )
653
- expect ( nodes . length ) . toBe ( 2 )
702
+ expect ( nodes ) . toBe ( startNodes )
654
703
655
- compareChildren ( nodes , [ h ( 'div' ) , h ( 'span' ) ] )
656
704
compareChildren ( startNodes , [ h ( 'div' ) , h ( 'span' ) ] )
657
705
} )
658
706
@@ -677,10 +725,8 @@ describe('betweenChildren', () => {
677
725
} )
678
726
679
727
expect ( count ) . toBe ( 1 )
680
- expect ( Array . isArray ( nodes ) ) . toBe ( true )
681
- expect ( nodes . length ) . toBe ( 2 )
728
+ expect ( nodes ) . toBe ( startNodes )
682
729
683
- compareChildren ( nodes , [ h ( 'div' ) , h ( 'span' ) ] )
684
730
compareChildren ( startNodes , [ h ( 'div' ) , h ( 'span' ) ] )
685
731
} )
686
732
@@ -1171,6 +1217,32 @@ describe('betweenChildren', () => {
1171
1217
]
1172
1218
] )
1173
1219
} )
1220
+
1221
+ it ( 'betweenChildren - 2bea' , ( ) => {
1222
+ let count = 0
1223
+
1224
+ const startNodes = [ [ 'Text' ] , [ createTextVNode ( 'Text' ) ] ]
1225
+
1226
+ const nodes = betweenChildren ( startNodes , ( before , after ) => {
1227
+ count ++
1228
+
1229
+ expect ( isVNode ( before ) ) . toBe ( true )
1230
+ expect ( isVNode ( after ) ) . toBe ( true )
1231
+
1232
+ expect ( getText ( before ) ) . toBe ( 'Text' )
1233
+ expect ( getText ( after ) ) . toBe ( 'Text' )
1234
+ } )
1235
+
1236
+ expect ( count ) . toBe ( 1 )
1237
+
1238
+ expect ( nodes ) . toHaveLength ( 2 )
1239
+ expect ( Array . isArray ( nodes [ 0 ] ) ) . toBe ( true )
1240
+ expect ( nodes [ 0 ] ) . toHaveLength ( 1 )
1241
+ expect ( isVNode ( ( nodes [ 0 ] as VNodeArrayChildren ) [ 0 ] ) ) . toBe ( true )
1242
+ expect ( nodes [ 1 ] ) . toBe ( startNodes [ 1 ] )
1243
+
1244
+ expect ( startNodes [ 0 ] [ 0 ] ) . toBe ( 'Text' )
1245
+ } )
1174
1246
} )
1175
1247
1176
1248
describe ( 'someChild' , ( ) => {
0 commit comments