@@ -60,6 +60,36 @@ describe('toChildArray', () => {
6060 expect ( scratch . innerHTML ) . to . equal ( '<div></div>' ) ;
6161 } ) ;
6262
63+ it ( 'filters nullish and boolean values' , ( ) => {
64+ expect ( toChildArray ( null ) ) . to . deep . equal ( [ ] ) ;
65+ expect ( toChildArray ( undefined ) ) . to . deep . equal ( [ ] ) ;
66+ expect ( toChildArray ( false ) ) . to . deep . equal ( [ ] ) ;
67+ expect ( toChildArray ( true ) ) . to . deep . equal ( [ ] ) ;
68+ } ) ;
69+
70+ it ( 'preserves zero and empty string values' , ( ) => {
71+ expect ( toChildArray ( 0 ) ) . to . deep . equal ( [ 0 ] ) ;
72+ expect ( toChildArray ( '' ) ) . to . deep . equal ( [ '' ] ) ;
73+ } ) ;
74+
75+ it ( 'flattens sparse nested arrays' , ( ) => {
76+ const nested = [ 0 , '' ] ;
77+ nested . length = 3 ;
78+ const sparse = [ null ] ;
79+ sparse [ 2 ] = [ undefined , false , nested ] ;
80+ sparse [ 4 ] = true ;
81+ sparse [ 6 ] = 'last' ;
82+
83+ expect ( toChildArray ( sparse ) ) . to . deep . equal ( [ 0 , '' , 'last' ] ) ;
84+ } ) ;
85+
86+ it ( 'flattens Array subclasses' , ( ) => {
87+ class ChildrenArray extends Array { }
88+ const children = new ChildrenArray ( 'first' , [ null , 'second' ] ) ;
89+
90+ expect ( toChildArray ( children ) ) . to . deep . equal ( [ 'first' , 'second' ] ) ;
91+ } ) ;
92+
6393 it ( 'should skip a function child' , ( ) => {
6494 const child = num => num . toFixed ( 2 ) ;
6595 render ( < Foo > { child } </ Foo > , scratch ) ;
0 commit comments