Last active
February 5, 2024 21:43
-
-
Save Julianhm9612/474c53ec010fd9acdc718064dd2781c4 to your computer and use it in GitHub Desktop.
Jest - Mock useQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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