Last active
February 5, 2024 21:52
-
-
Save Julianhm9612/e9315f5cd4325e995411529d67afd46d to your computer and use it in GitHub Desktop.
Jest - Mock custom hook
This file contains hidden or 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 mockData = { | |
something: 'value' | |
}; | |
const mockUseSomething = jest.fn().mockReturnValue({ | |
data: mockData, | |
isLoading: false, | |
isSuccess: true, | |
refetch: () => mockUseSomething | |
}); | |
jest.mock('~/hooks/useSomething', () => ({ | |
useSomething: jest.fn() | |
})); | |
(usePolicyURL as jest.Mock).mockImplementation(mockUseSomething); | |
expect(mockUseSomething).toHaveBeenCalled(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment