this is jest unit test
ContextError: useModalStyles returned is 'undefined'. Seems you forgot to wrap the components in ""
jest.mock('@chakra-ui/react', () => {
const originalModule = jest.requireActual('@chakra-ui/react');
return {
...originalModule,
useModalStyles: jest.fn(() => ({}))
};
});
describe('AppPage Component', () => {
const eventId = 'your-event-id';
it('renders without crashing', () => {
const mockCalendarEventQueryData = {
data: {
calendarEvent: {
title: 'Mocked Event Title',
children: [],
members: []
}
}
};
(useCalendarEventQuery as jest.Mock).mockImplementation(() => ({
...mockCalendarEventQueryData
}));
// Mocking the useUpdateSessionMutation hook
render(<EditEvent eventId={eventId} />);
});
});
this is component
give me some suggestion to solve this error
You might have to wrap your tests in the
ChakraProviderlike was done for the app. This is part of their "Getting Started" documentation but also needs to be done in tests.The
useModalStyleshook (and other components that may be in the React tree) probably relies on information from that context to function.