@@ -224,10 +224,12 @@ describe('addProps', () => {
224224 expect ( child . type ) . toBe ( 'div' )
225225 expect ( child . props ?. class ) . toBe ( 'red' )
226226
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 )
231233 } )
232234
233235 it ( 'addProps - 3de9' , ( ) => {
@@ -380,14 +382,9 @@ describe('addProps', () => {
380382 compareChildren ( nullNodes , referenceNodes )
381383 compareChildren ( emptyNodes , referenceNodes )
382384
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 )
391388 } )
392389
393390 it ( 'addProps - a934' , ( ) => {
@@ -428,6 +425,33 @@ describe('addProps', () => {
428425 expect ( ( nodes [ 0 ] as VNode ) . props ?. class ) . toBe ( undefined )
429426 expect ( ( nodes [ 1 ] as VNode ) . props ?. class ) . toBe ( 'red' )
430427 } )
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+ } )
431455} )
432456
433457describe ( 'replaceChildren' , ( ) => {
@@ -450,9 +474,9 @@ describe('replaceChildren', () => {
450474 expect ( count ) . toBe ( 1 )
451475 expect ( Array . isArray ( nodes ) ) . toBe ( true )
452476 expect ( nodes ) . toHaveLength ( 1 )
477+ expect ( nodes ) . toBe ( startNodes )
453478
454479 compareChildren ( startNodes , [ h ( 'div' ) ] )
455- compareChildren ( nodes , [ h ( 'div' ) ] )
456480 } )
457481
458482 it ( 'replaceChildren - 7c8a' , ( ) => {
@@ -476,6 +500,7 @@ describe('replaceChildren', () => {
476500 expect ( nodes ) . toHaveLength ( 0 )
477501
478502 compareChildren ( startNodes , [ h ( 'div' ) ] )
503+ expect ( startNodes [ 0 ] ) . toBe ( startNode )
479504 } )
480505
481506 it ( 'replaceChildren - 1d16' , ( ) => {
@@ -601,6 +626,37 @@ describe('replaceChildren', () => {
601626 compareChildren ( startNodes , [ h ( 'div' ) , 'Text' , [ h ( 'span' ) , 'More text' ] ] )
602627 compareChildren ( nodes , [ h ( 'div' ) , '(Text)' , [ h ( 'span' ) , '(More text)' ] ] )
603628 } )
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+ } )
604660} )
605661
606662describe ( 'betweenChildren' , ( ) => {
@@ -615,17 +671,11 @@ describe('betweenChildren', () => {
615671 } )
616672
617673 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 )
622675
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 )
628677 expect ( startNodes [ 0 ] ) . toBe ( startNode )
678+ expect ( startNode . type ) . toBe ( 'div' )
629679 expect ( startNode . props ) . toBe ( null )
630680 } )
631681
@@ -649,10 +699,8 @@ describe('betweenChildren', () => {
649699 } )
650700
651701 expect ( count ) . toBe ( 1 )
652- expect ( Array . isArray ( nodes ) ) . toBe ( true )
653- expect ( nodes . length ) . toBe ( 2 )
702+ expect ( nodes ) . toBe ( startNodes )
654703
655- compareChildren ( nodes , [ h ( 'div' ) , h ( 'span' ) ] )
656704 compareChildren ( startNodes , [ h ( 'div' ) , h ( 'span' ) ] )
657705 } )
658706
@@ -677,10 +725,8 @@ describe('betweenChildren', () => {
677725 } )
678726
679727 expect ( count ) . toBe ( 1 )
680- expect ( Array . isArray ( nodes ) ) . toBe ( true )
681- expect ( nodes . length ) . toBe ( 2 )
728+ expect ( nodes ) . toBe ( startNodes )
682729
683- compareChildren ( nodes , [ h ( 'div' ) , h ( 'span' ) ] )
684730 compareChildren ( startNodes , [ h ( 'div' ) , h ( 'span' ) ] )
685731 } )
686732
@@ -1171,6 +1217,32 @@ describe('betweenChildren', () => {
11711217 ]
11721218 ] )
11731219 } )
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+ } )
11741246} )
11751247
11761248describe ( 'someChild' , ( ) => {
0 commit comments