I ran into something in this category with mocking a module with jest.mock().
jest.mock()
import { fetchResource } from 'utils/api' jest.mock('utils/api')
This alone is enough to mock fetchResource, but with TypeScript we still get the intellisense from the original function rather than the mock function. I just reassigned fetchResource and typed the new function:
fetchResource
import { fetchResource } from 'utils/api' jest.mock('utils/api') const mockFetch = fetchResource as jest.Mock
Finally I had access to things like fetchResource.mockResolvedValueOnce()
fetchResource.mockResolvedValueOnce()
Cool, learned something new today, thank you =)
You just ended my hour long search for a solution. Many thanks!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I ran into something in this category with mocking a module with
jest.mock()
.This alone is enough to mock
fetchResource
, but with TypeScript we still get the intellisense from the original function rather than the mock function. I just reassignedfetchResource
and typed the new function:Finally I had access to things like
fetchResource.mockResolvedValueOnce()
Cool, learned something new today, thank you =)
You just ended my hour long search for a solution. Many thanks!