I'm trying to use jest-when to mock out requests made with Axios, but am having trouble with the Typescript typings when trying to use mockResolvedValue. See example snippets below:
jest.mock('axios')
const mockedAxios = axios as jest.Mocked<typeof axios>;
// doesn't work
when(mockedAxios.get)
.calledWith('http://some-api')
.mockResolvedValue('foo'); // complains that "Argument of type '"foo"' is not assignable to parameter of type 'never'.ts(2345)"
// this seems to work w/ the generic type hint, but is super ugly...
when<Promise<unknown>, any[]>(mockedAxios.get)
.calledWith('http://some-api')
.mockResolvedValue('foo');
I think it might have something to do with when(mockedAxios.get) resolving to WhenMock<unknown, [string, AxiosRequestConfig?]> (T being unknown specifically), but am kinda stumped.
Any ideas or suggestions?
Thanks