Skip to content

Instantly share code, notes, and snippets.

@Julianhm9612
Last active February 5, 2024 21:43
Show Gist options
  • Save Julianhm9612/474c53ec010fd9acdc718064dd2781c4 to your computer and use it in GitHub Desktop.
Save Julianhm9612/474c53ec010fd9acdc718064dd2781c4 to your computer and use it in GitHub Desktop.
Jest - Mock useQuery
// Method 1
const mockRefetch = jest.fn();
jest.mock('react-query', () => ({
useQuery: jest.fn().mockReturnValue(({ data: { ...MockData }, isLoading: false, isSuccess: true, refetch: () => mockRefetch }))
}));
// Method 2
const mockRefetch = jest.fn();
jest
.spyOn(ReactQuery, 'useQuery')
.mockImplementation(
jest
.fn()
.mockReturnValue({ data: { ...MockData }, isLoading: false, isSuccess: true, refetch: () => mockRefetch })
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment