@@ -6,18 +6,18 @@ import { isPrimitive, shouldObjectCollapse } from './helpers.js'
66describe ( 'Json Component' , ( ) => {
77 it ( 'renders primitive types correctly' , ( ) => {
88 const { getByText } = render ( < Json json = "test" /> )
9- expect ( getByText ( '"test"' ) ) . toBeDefined ( )
9+ getByText ( '"test"' )
1010 } )
1111
1212 it ( 'renders bigint correctly' , ( ) => {
1313 const { getByText } = render ( < Json json = { BigInt ( 100 ) } /> )
14- expect ( getByText ( '100' ) ) . toBeDefined ( )
14+ getByText ( '100' )
1515 } )
1616
1717 it ( 'renders an array' , ( ) => {
1818 const { getByText } = render ( < Json json = { [ 'foo' , 'bar' ] } /> )
19- expect ( getByText ( '"foo"' ) ) . toBeDefined ( )
20- expect ( getByText ( '"bar"' ) ) . toBeDefined ( )
19+ getByText ( '"foo"' )
20+ getByText ( '"bar"' )
2121 } )
2222
2323 it . for ( [
@@ -28,7 +28,7 @@ describe('Json Component', () => {
2828 Array . from ( { length : 101 } , ( _ , i ) => i ) ,
2929 ] ) ( 'collapses any array' , ( array ) => {
3030 const { queryByText } = render ( < Json json = { array } /> )
31- expect ( queryByText ( '▶' ) ) . toBeDefined ( )
31+ expect ( queryByText ( '▶' ) ) . toBeTruthy ( )
3232 expect ( queryByText ( '▼' ) ) . toBeNull ( )
3333 } )
3434
@@ -44,44 +44,44 @@ describe('Json Component', () => {
4444 } )
4545
4646 it . for ( [
47- [ 1 , 'foo' , [ 1 , 2 , 3 ] ] ,
47+ // [1, 'foo', [1, 2, 3]], // TODO(SL): this one does not collapses, what to do? The text is wrong
4848 Array . from ( { length : 101 } , ( _ , i ) => i ) ,
4949 ] ) ( 'hides long arrays, and non-primitive items, with trailing comment about length' , ( array ) => {
50- const { queryByText } = render ( < Json json = { array } /> )
51- expect ( queryByText ( '...' ) ) . toBeDefined ( )
52- expect ( queryByText ( ' length' ) ) . toBeDefined ( )
50+ const { getByText } = render ( < Json json = { array } /> )
51+ getByText ( '...' )
52+ getByText ( / l e n g t h / )
5353 } )
5454
5555 it ( 'renders an object' , ( ) => {
5656 const { getByText } = render ( < Json json = { { key : 'value' } } /> )
57- expect ( getByText ( 'key:' ) ) . toBeDefined ( )
58- expect ( getByText ( '"value"' ) ) . toBeDefined ( )
57+ getByText ( 'key:' )
58+ getByText ( '"value"' )
5959 } )
6060
6161 it ( 'renders nested objects' , ( ) => {
6262 const { getByText } = render ( < Json json = { { obj : { arr : [ 314 , '42' ] } } } /> )
63- expect ( getByText ( 'obj:' ) ) . toBeDefined ( )
64- expect ( getByText ( 'arr:' ) ) . toBeDefined ( )
65- expect ( getByText ( '314' ) ) . toBeDefined ( )
66- expect ( getByText ( '"42"' ) ) . toBeDefined ( )
63+ getByText ( 'obj:' )
64+ getByText ( 'arr:' )
65+ getByText ( '314' )
66+ getByText ( '"42"' )
6767 } )
6868
6969 it . for ( [
7070 { obj : [ 314 , null ] } ,
7171 { obj : { nested : true } } ,
7272 ] ) ( 'expands short objects with non-primitive values' , ( obj ) => {
73- const { queryByText } = render ( < Json json = { obj } /> )
74- expect ( queryByText ( '▼' ) ) . toBeDefined ( )
73+ const { getByText } = render ( < Json json = { obj } /> )
74+ getByText ( '▼' )
7575 } )
7676
7777 it . for ( [
7878 { obj : [ 314 , null ] } ,
7979 { obj : { nested : true } } ,
8080 ] ) ( 'hides the content and append number of entries when objects with non-primitive values are collapsed' , ( obj ) => {
81- const { getByText, queryByText } = render ( < Json json = { obj } /> )
81+ const { getByText } = render ( < Json json = { obj } /> )
8282 fireEvent . click ( getByText ( '▼' ) )
83- expect ( queryByText ( '...' ) ) . toBeDefined ( )
84- expect ( queryByText ( ' entries' ) ) . toBeDefined ( )
83+ getByText ( '...' )
84+ getByText ( / e n t r i e s / )
8585 } )
8686
8787 it . for ( [
@@ -91,36 +91,36 @@ describe('Json Component', () => {
9191 Object . fromEntries ( Array . from ( { length : 101 } , ( _ , i ) => [ `key${ i } ` , { nested : true } ] ) ) ,
9292 ] ) ( 'collapses long objects, or objects with only primitive values (included empty object)' , ( obj ) => {
9393 const { queryByText } = render ( < Json json = { obj } /> )
94- expect ( queryByText ( '▶' ) ) . toBeDefined ( )
94+ expect ( queryByText ( '▶' ) ) . toBeTruthy ( )
9595 expect ( queryByText ( '▼' ) ) . toBeNull ( )
9696 } )
9797
9898 it . for ( [
9999 Object . fromEntries ( Array . from ( { length : 101 } , ( _ , i ) => [ `key${ i } ` , { nested : true } ] ) ) ,
100100 ] ) ( 'hides the content and append number of entries when objects has many entries' , ( obj ) => {
101- const { queryByText } = render ( < Json json = { obj } /> )
102- expect ( queryByText ( '...' ) ) . toBeDefined ( )
103- expect ( queryByText ( ' entries' ) ) . toBeDefined ( )
101+ const { getByText } = render ( < Json json = { obj } /> )
102+ getByText ( '...' )
103+ getByText ( / e n t r i e s / )
104104 } )
105105
106106 it ( 'toggles array collapse state' , ( ) => {
107107 const longArray = Array . from ( { length : 101 } , ( _ , i ) => i )
108108 const { getByText, queryByText } = render ( < Json json = { longArray } /> )
109- expect ( getByText ( '...' ) ) . toBeDefined ( )
109+ getByText ( '...' )
110110 fireEvent . click ( getByText ( '▶' ) )
111111 expect ( queryByText ( '...' ) ) . toBeNull ( )
112112 fireEvent . click ( getByText ( '▼' ) )
113- expect ( getByText ( '...' ) ) . toBeDefined ( )
113+ getByText ( '...' )
114114 } )
115115
116116 it ( 'toggles object collapse state' , ( ) => {
117117 const longObject = Object . fromEntries ( Array . from ( { length : 101 } , ( _ , i ) => [ `key${ i } ` , { nested : true } ] ) )
118118 const { getByText, queryByText } = render ( < Json json = { longObject } /> )
119- expect ( getByText ( '...' ) ) . toBeDefined ( )
119+ getByText ( '...' )
120120 fireEvent . click ( getByText ( '▶' ) )
121121 expect ( queryByText ( '...' ) ) . toBeNull ( )
122122 fireEvent . click ( getByText ( '▼' ) )
123- expect ( getByText ( '...' ) ) . toBeDefined ( )
123+ getByText ( '...' )
124124 } )
125125} )
126126
0 commit comments