Skip to content

TypeError: Cannot read properties of null (reading 'useContext') #2266

Open
@jean-smaug

Description

@jean-smaug

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 in 0.2.37

Image

Image

There are some issues, on invalid calls of hooks too

Image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopenapi-react-queryRelevant to openapi-react-query

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions