@@ -55,19 +55,25 @@ describe('Accordion', () => {
5555 expect ( screen . getByText ( 'is' ) ) . not . toHaveAttribute ( 'hidden' ) ;
5656 } ) ;
5757
58- test ( 'renders component when header and content are invalid' , ( ) => {
59- // @ts -expect-error: title and content should be a string and ReactNode, respectively
60- const { rerender } = render ( < Accordion items = { [ { title : 28 , content : { key : 'value' } } ] } /> ) ;
61- expect ( screen . getByText ( 28 ) ) . toBeInTheDocument ( ) ;
62- expect ( screen . getByText ( 'Accordion content must be a valid React element' ) ) . toBeInTheDocument ( ) ;
58+ describe ( 'props to render are invalid' , ( ) => {
59+ beforeEach ( ( ) => {
60+ console . error = jest . fn ( ) ;
61+ } ) ;
6362
64- // @ts -expect-error: title and content should be a string and ReactNode, respectively
65- rerender ( < Accordion items = { [ { title : { hi : 'bye' } , content : ( ) => { } } ] } /> ) ;
66- expect ( screen . getByText ( 'Accordion title must be a valid string' ) ) . toBeInTheDocument ( ) ;
67- expect ( screen . getByText ( 'Accordion content must be a valid React element' ) ) . toBeInTheDocument ( ) ;
63+ test ( 'renders accordion when title and content are invalid' , ( ) => {
64+ // @ts -expect-error: title and content should be a string and ReactNode, respectively
65+ render ( < Accordion items = { [ { title : { hi : 'bye' } , content : ( ) => { } } ] } /> ) ;
66+ expect ( console . error ) . toHaveBeenCalledWith ( 'title is not a valid React node' ) ;
67+ expect ( console . error ) . toHaveBeenCalledWith ( 'content is not a valid React node' ) ;
68+ } ) ;
6869
69- // @ts -expect-error: item should contain title and content keys
70- rerender ( < Accordion items = { [ { extra : '' } ] } /> ) ;
71- expect ( screen . getByTestId ( 'accordion-root' ) ) . toBeInTheDocument ( ) ;
70+ test ( 'renders accordion when title and content are missing' , ( ) => {
71+ // @ts -expect-error: item should contain title and content keys
72+ render ( < Accordion items = { [ { extra : '' } ] } /> ) ;
73+ expect ( screen . getByTestId ( 'accordion-root' ) ) . toBeInTheDocument ( ) ;
74+ // nothing is printed to the console since a value is undefined if it's not given and undefined
75+ // is a valid React node
76+ expect ( console . error ) . not . toHaveBeenCalled ( ) ;
77+ } ) ;
7278 } ) ;
7379} ) ;
0 commit comments