I need to test a component(ServiceRequestDetails).That component has a layout that uses AppCOntext data.
While testing ServiceRequestDetails I got the error
TypeError: Cannot read properties of undefined (reading 'darkMode')..
ServiceRequestDetails.js
Page. From here I tested text "Service Request Details".But I got an error.Because in the layout component I used Appcontext.
export function ServiceRequestDetails(props) {
const ctx = useContext(AppContext);
return (
<>
<Layout
page="servicerequestdetails"
title={navigationLinks()}
subTitle={pageSubTitle()}
showHelp={true}
helpText={"Help"}
helpIcon={<QuestionCircleOutlined />}
onHelpClick={() => setShowHelpModal(!showHelpModal)}
helpToggle={showHelpModal}
helpTemplate={<ViewServiceRequest />}
>
<div className="flex items-center">
<div className="pr-2">
<img src="/images/icons/services.svg" alt="filter" />
</div>
<h3 className="text-lg font-medium">Service Request Details</h3>
</div>
</Layout>
</>
)
}
ServiceRequestDetails.test.js
.It is my test case for service request details page.
From here how to resolve AppCOntext issue.
test('Testing For title', () => {
render(
<Router>
<ServiceRequestDetails/>
</Router>
)
expect(screen.getByText("Service Request Details")).toBeInTheDocument();
})