File tree Expand file tree Collapse file tree 2 files changed +14
-28
lines changed
src/components/content-presentation/table/components/__tests__ Expand file tree Collapse file tree 2 files changed +14
-28
lines changed Original file line number Diff line number Diff line change 11import { render } from '@testing-library/react' ;
2- import { useContext } from 'react' ;
32import { TableBody } from '..' ;
43import { Table , TableSection , TableSectionContext } from '../..' ;
54
@@ -15,26 +14,20 @@ describe('Table.Body', () => {
1514 } ) ;
1615
1716 it ( 'exposes TableSectionContext' , ( ) => {
18- let tableSection : TableSection = TableSection . NONE ;
19-
20- const TestComponent = ( ) => {
21- const tableContext = useContext ( TableSectionContext ) ;
22-
23- if ( tableSection !== tableContext ) {
24- tableSection = tableContext ;
25- }
26-
27- return null ;
28- } ;
17+ const mock = jest . fn ( ) ;
2918
3019 render (
3120 < Table >
3221 < TableBody >
33- < TestComponent />
22+ < TableSectionContext . Consumer >
23+ { ( section ) => {
24+ return mock ( section ) ;
25+ } }
26+ </ TableSectionContext . Consumer >
3427 </ TableBody >
3528 </ Table > ,
3629 ) ;
3730
38- expect ( tableSection ) . toBe ( TableSection . BODY ) ;
31+ expect ( mock ) . toHaveBeenCalledWith ( TableSection . BODY ) ;
3932 } ) ;
4033} ) ;
Original file line number Diff line number Diff line change 11import { render } from '@testing-library/react' ;
2- import { useContext } from 'react' ;
32import { TableHead } from '..' ;
43import { Table , TableSection , TableSectionContext } from '../..' ;
54
@@ -15,26 +14,20 @@ describe('Table.Head', () => {
1514 } ) ;
1615
1716 it ( 'exposes TableSectionContext' , ( ) => {
18- let tableSection : TableSection = TableSection . NONE ;
19-
20- const TestComponent = ( ) => {
21- const tableContext = useContext ( TableSectionContext ) ;
22-
23- if ( tableSection !== tableContext ) {
24- tableSection = tableContext ;
25- }
26-
27- return null ;
28- } ;
17+ const mock = jest . fn ( ) ;
2918
3019 render (
3120 < Table >
3221 < TableHead >
33- < TestComponent />
22+ < TableSectionContext . Consumer >
23+ { ( section ) => {
24+ return mock ( section ) ;
25+ } }
26+ </ TableSectionContext . Consumer >
3427 </ TableHead >
3528 </ Table > ,
3629 ) ;
3730
38- expect ( tableSection ) . toBe ( TableSection . HEAD ) ;
31+ expect ( mock ) . toHaveBeenCalledWith ( TableSection . HEAD ) ;
3932 } ) ;
4033} ) ;
You can’t perform that action at this time.
0 commit comments