1- import React from 'react' ;
1+ import React , { ReactNode } from 'react' ;
22import { render , screen } from '@testing-library/react' ;
33import HomePage from '../HomePage' ;
44import PatientDetails from '@components/patient/PatientDetails' ;
55import ConditionsTable from '@components/conditions/ConditionsTable' ;
66import { useClinicalConfig } from '@hooks/useClinicalConfig' ;
77import { validFullClinicalConfig } from '@__mocks__/configMocks' ;
88
9+ // Mock React.Suspense to render children immediately in tests
10+ jest . mock ( 'react' , ( ) => ( {
11+ ...jest . requireActual ( 'react' ) ,
12+ Suspense : ( { children } : { children : ReactNode } ) => children ,
13+ } ) ) ;
14+
915// Mock Carbon components
1016jest . mock ( '@carbon/react' , ( ) => ( {
1117 Grid : jest . fn ( ( { children } ) => (
@@ -67,7 +73,7 @@ describe('HomePage Component', () => {
6773 ) . not . toBeInTheDocument ( ) ;
6874 } ) ;
6975
70- it ( 'should render with correct Carbon layout structure when config is loaded' , ( ) => {
76+ it ( 'should render with correct Carbon layout structure when config is loaded' , async ( ) => {
7177 // Mock useClinicalConfig to return config
7278 ( useClinicalConfig as jest . Mock ) . mockReturnValue ( {
7379 clinicalConfig : validFullClinicalConfig ,
@@ -76,12 +82,12 @@ describe('HomePage Component', () => {
7682 render ( < HomePage /> ) ;
7783
7884 // Should render Carbon layout components
79- expect ( screen . getByTestId ( 'carbon-section' ) ) . toBeInTheDocument ( ) ;
80- expect ( screen . getByTestId ( 'carbon-grid' ) ) . toBeInTheDocument ( ) ;
81- expect ( screen . getByTestId ( 'carbon-column' ) ) . toBeInTheDocument ( ) ;
85+ expect ( await screen . findByTestId ( 'carbon-section' ) ) . toBeInTheDocument ( ) ;
86+ expect ( await screen . findByTestId ( 'carbon-grid' ) ) . toBeInTheDocument ( ) ;
87+ expect ( await screen . findByTestId ( 'carbon-column' ) ) . toBeInTheDocument ( ) ;
8288 } ) ;
8389
84- it ( 'should render child components when config is loaded' , ( ) => {
90+ it ( 'should render child components when config is loaded' , async ( ) => {
8591 // Mock useClinicalConfig to return config
8692 ( useClinicalConfig as jest . Mock ) . mockReturnValue ( {
8793 clinicalConfig : validFullClinicalConfig ,
@@ -91,12 +97,20 @@ describe('HomePage Component', () => {
9197
9298 // Should render child components
9399 expect ( PatientDetails ) . toHaveBeenCalled ( ) ;
94- expect ( screen . getByTestId ( 'mocked-patient-details' ) ) . toBeInTheDocument ( ) ;
95- expect ( screen . getByText ( 'Mocked PatientDetails' ) ) . toBeInTheDocument ( ) ;
100+ expect (
101+ await screen . findByTestId ( 'mocked-patient-details' ) ,
102+ ) . toBeInTheDocument ( ) ;
103+ expect (
104+ await screen . findByText ( 'Mocked PatientDetails' ) ,
105+ ) . toBeInTheDocument ( ) ;
96106
97107 expect ( ConditionsTable ) . toHaveBeenCalled ( ) ;
98- expect ( screen . getByTestId ( 'mocked-conditions-table' ) ) . toBeInTheDocument ( ) ;
99- expect ( screen . getByText ( 'Mocked ConditionsTable' ) ) . toBeInTheDocument ( ) ;
108+ expect (
109+ await screen . findByTestId ( 'mocked-conditions-table' ) ,
110+ ) . toBeInTheDocument ( ) ;
111+ expect (
112+ await screen . findByText ( 'Mocked ConditionsTable' ) ,
113+ ) . toBeInTheDocument ( ) ;
100114 } ) ;
101115
102116 it ( 'should match snapshot when loading' , ( ) => {
0 commit comments