@@ -36,14 +36,15 @@ describe('Json Component', () => {
3636 [ 'foo' , 'bar' ] ,
3737 [ ] ,
3838 [ 1 , 2 , 3 ] ,
39+ [ 1 , 'foo' , null , undefined ] ,
3940 ] ) ( 'shows short arrays of primitive items, without trailing comment about length' , ( array ) => {
4041 const { queryByText } = render ( < Json json = { array } /> )
4142 expect ( queryByText ( '...' ) ) . toBeNull ( )
4243 expect ( queryByText ( 'length' ) ) . toBeNull ( )
4344 } )
4445
4546 it . for ( [
46- [ 1 , 'foo' , null ] ,
47+ [ 1 , 'foo' , [ 1 , 2 , 3 ] ] ,
4748 Array . from ( { length : 101 } , ( _ , i ) => i ) ,
4849 ] ) ( 'hides long arrays, and non-primitive items, with trailing comment about length' , ( array ) => {
4950 const { queryByText } = render ( < Json json = { array } /> )
@@ -66,8 +67,6 @@ describe('Json Component', () => {
6667 } )
6768
6869 it . for ( [
69- { obj : undefined } ,
70- { obj : null } ,
7170 { obj : [ 314 , null ] } ,
7271 { obj : { nested : true } } ,
7372 ] ) ( 'expands short objects with non-primitive values' , ( obj ) => {
@@ -76,8 +75,6 @@ describe('Json Component', () => {
7675 } )
7776
7877 it . for ( [
79- { obj : undefined } ,
80- { obj : null } ,
8178 { obj : [ 314 , null ] } ,
8279 { obj : { nested : true } } ,
8380 ] ) ( 'hides the content and append number of entries when objects with non-primitive values are collapsed' , ( obj ) => {
@@ -90,7 +87,7 @@ describe('Json Component', () => {
9087 it . for ( [
9188 { } ,
9289 { a : 1 , b : 2 } ,
93- { a : 1 , b : true } ,
90+ { a : 1 , b : true , c : null , d : undefined } ,
9491 Object . fromEntries ( Array . from ( { length : 101 } , ( _ , i ) => [ `key${ i } ` , { nested : true } ] ) ) ,
9592 ] ) ( 'collapses long objects, or objects with only primitive values (included empty object)' , ( obj ) => {
9693 const { queryByText } = render ( < Json json = { obj } /> )
@@ -107,25 +104,23 @@ describe('Json Component', () => {
107104 } )
108105
109106 it ( 'toggles array collapse state' , ( ) => {
110- const { getByText , queryByText } = render ( < Json json = { [ 'foo' , null ] } /> )
111- expect ( getByText ( '"foo"' ) ) . toBeDefined ( )
112- expect ( queryByText ( 'null ') ) . toBeNull ( )
107+ const longArray = Array . from ( { length : 101 } , ( _ , i ) => i )
108+ const { getByText, queryByText } = render ( < Json json = { longArray } /> )
109+ expect ( getByText ( '... ') ) . toBeDefined ( )
113110 fireEvent . click ( getByText ( '▶' ) )
114- expect ( getByText ( 'null ') ) . toBeDefined ( )
111+ expect ( queryByText ( '... ') ) . toBeNull ( )
115112 fireEvent . click ( getByText ( '▼' ) )
116- expect ( getByText ( '"foo"' ) ) . toBeDefined ( )
117- expect ( queryByText ( 'null' ) ) . toBeNull ( )
113+ expect ( getByText ( '...' ) ) . toBeDefined ( )
118114 } )
119115
120116 it ( 'toggles object collapse state' , ( ) => {
121- const { getByText , queryByText } = render ( < Json json = { { key : 'value' } } /> )
122- expect ( getByText ( 'key:' ) ) . toBeDefined ( )
123- expect ( getByText ( '"value" ' ) ) . toBeDefined ( )
117+ const longObject = Object . fromEntries ( Array . from ( { length : 101 } , ( _ , i ) => [ `key ${ i } ` , { nested : true } ] ) )
118+ const { getByText, queryByText } = render ( < Json json = { longObject } /> )
119+ expect ( getByText ( '... ' ) ) . toBeDefined ( )
124120 fireEvent . click ( getByText ( '▶' ) )
125- expect ( queryByText ( 'key: "value" ' ) ) . toBeNull ( )
121+ expect ( queryByText ( '... ' ) ) . toBeNull ( )
126122 fireEvent . click ( getByText ( '▼' ) )
127- expect ( getByText ( 'key:' ) ) . toBeDefined ( )
128- expect ( getByText ( '"value"' ) ) . toBeDefined ( )
123+ expect ( getByText ( '...' ) ) . toBeDefined ( )
129124 } )
130125} )
131126
@@ -135,8 +130,8 @@ describe('isPrimitive', () => {
135130 expect ( isPrimitive ( 42 ) ) . toBe ( true )
136131 expect ( isPrimitive ( true ) ) . toBe ( true )
137132 expect ( isPrimitive ( 1n ) ) . toBe ( true )
138- expect ( isPrimitive ( null ) ) . toBe ( false )
139- expect ( isPrimitive ( undefined ) ) . toBe ( false )
133+ expect ( isPrimitive ( null ) ) . toBe ( true )
134+ expect ( isPrimitive ( undefined ) ) . toBe ( true )
140135 expect ( isPrimitive ( { } ) ) . toBe ( false )
141136 expect ( isPrimitive ( [ ] ) ) . toBe ( false )
142137 } )
0 commit comments