Open
Description
openapi-react-query version
0.3.1
Description
I'm building a React packages in order to share clients initialization across multiple apps
Inside those apps I try to make unit tests with Jest and I encountered the error in title TypeError: Cannot read properties of null (reading 'useContext')
Technical context :
- Monorepo managed with PNPM
10.8.1
- Node
v22.14.0
- jest
29.7.0
- Transpiler for unit tests
@swc/jest
in0.2.37
There are some issues, on invalid calls of hooks too
Reproduction
import createFetchClient from "openapi-fetch";
import createClient from "openapi-react-query";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { render } from "@testing-library/react";
import type MetadataService from "../../types/MetadataService";
const metadataClient = createClient(createFetchClient<MetadataService.paths>());
const TechnicalProof = () => {
const { data: countries } = metadataClient.useQuery("get", "/v1/countries");
console.log("🚀 ~ TechnicalProof ~ countries:", countries);
return <div>Hello</div>;
};
describe("Example", () => {
it("should render a component that use SDKs", () => {
render(
<QueryClientProvider client={new QueryClient()}>
<TechnicalProof />
</QueryClientProvider>,
);
});
});
Expected result
Understand this issue
Extra
- I’m willing to open a PR (see CONTRIBUTING.md)