Skip to content
Discussion options

You must be logged in to vote

Nothing like a good night’s sleep to get the problems solved automagically 😄

The solution is just mock queryClient in a separated file and then import it at top level of the test file.

// useQuery.mock.ts
export const queryClient = {
  invalidateQueries: jest.fn(),
};

const useQueryClient = jest.fn().mockImplementation(() => queryClient);

jest.doMock("react-query", () => ({
  ...jest.requireActual("react-query"),
  useQueryClient,
}));

and in my test file

// ProductApplicationModal.test.ts
import { queryClient } from "shared/hooks/mocks";



expect(queryClient.invalidateQueries).toHaveBeenCalled(); // success

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by joel-daros
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants