TypeScript says mockResolvedValue does not exist on an axios or fetch function
Property 'mockResolvedValue' does not exist on type '<T = any, R = AxiosResponse<T, any>, D = any>(url: string, config?: AxiosRequestConfig<D>) => Promise<R>'Short answer
TypeScript sees axios.get as a normal function, not a Jest mock, so it has no mockResolvedValue. The module is mocked at run time but not in the types. Mock the module with jest.mock, then wrap the function with jest.mocked(), or type the module with jest.Mocked, so the mock methods appear.
Fix it fast
1Find out which cause you have
Check that the module is mocked at all, then look at how the function is referenced in the failing line.
grep -n "jest.mock" path/to/file.test.ts grep -n "mockResolvedValue" path/to/file.test.ts2Match what you see, then jump to its fix
- 1
The error names the function's own signature, such as axios.get, and the test calls axios.get.mockResolvedValue(...).The function is not typed as a Jest mockFix - 2
You set up several functions of the same module and every line gives the same error.The whole module needs the mocked typeFix - 3
The mock is created with jest.fn() and mockResolvedValue rejects the value you pass.A hand-made jest.fn() has no return type to resolveFix
- 1
What does the error look like?
Property 'mockResolvedValue' does not exist on type '<T = any, R = AxiosResponse<T, any>, D = any>(url: string, config?: AxiosRequestConfig<D>) => Promise<R>'
Cause 1 of 3
The function is not typed as a Jest mock
1Check
Jest's docs say jest.mocked() wraps the types of the source object and its nested members with type definitions of Jest mock functions.
grep -n "axios" path/to/file.test.ts2Fix
Mock the module, then wrap the member you set up in jest.mocked().
import axios from 'axios';
jest.mock('axios');
const mockedGet = jest.mocked(axios.get);
mockedGet.mockResolvedValue({ data: { id: 1 } });3Verify
Run the test file; the type error is gone and the mock returns the value.
npx jest path/to/file.test.tsConfirmed by jestjs.io
Cause 2 of 3
The whole module needs the mocked type
1Check
The jest.Mocked<Source> utility type returns the source type wrapped with Jest mock function types, so one declaration covers the module.
grep -n "jest.Mocked" path/to/file.test.ts2Fix
Declare the module once as jest.Mocked and call the mock methods on it.
import axios from 'axios';
jest.mock('axios');
const mockedAxios = axios as jest.Mocked<typeof axios>;
mockedAxios.get.mockResolvedValue({ data: [] });3Verify
Run the test; the line compiles and your code receives the data.
npx jest path/to/file.test.tsConfirmed by jestjs.io
Cause 3 of 3
A hand-made jest.fn() has no return type to resolve
1Check
With Jest's TypeScript setup, jest.fn takes the function type as a type argument; the docs import jest from @jest/globals for this.
grep -n "jest.fn" path/to/file.test.ts2Fix
Give jest.fn the function type it should have, so mockResolvedValue knows the resolved type.
import { jest, test } from '@jest/globals';
const getUser = jest.fn<() => Promise<number>>().mockResolvedValue(43);3Verify
Run the test file.
npx jest path/to/file.test.tsConfirmed by jestjs.io
How do I stop it coming back?
- Call jest.mock for a module before you use jest.mocked on its members.
- Create typed mocks in one test helper file and import them, so every test uses the same pattern.
- Import Jest APIs from @jest/globals in TypeScript projects, as the Jest docs do for their TypeScript examples.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
jest.mock() works at the top of the file but not inside a test
Mock works in one test and returns undefined in the next
Jest hoists jest.mock() only to the top of its own code block.
3 causes, each with a fixWeb apps
tsconfig rejects allowImportingTsExtensions
An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly
allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.
2 causes, each with a fixWeb apps
TypeScript refuses JSX because the jsx option is not set
TS17004: Cannot use JSX unless the '--jsx' flag is provided.
TypeScript compiles JSX only when you name the file with a .tsx extension and enable the jsx compiler option.
2 causes, each with a fixWeb apps
TypeScript rejects a component that returns an array or other non-Element
Its return type 'Element[]' is not a valid JSX element.
TypeScript before 5.1 required every component to return JSX.Element or null, so arrays, strings and Promises were rejected even though React renders them.
2 causes, each with a fixWeb apps
Cypress refuses to start with 'Your configFile is invalid'
Your configFile threw an error from: /path/to/cypress.config.ts
Cypress could not load cypress.config.js or .ts, or found something wrong in it.
5 causes, each with a fixWeb apps
ESLint cannot decide which copy of the @typescript-eslint plugin to use
The message lists two file paths for the same plugin, each with the name of the config that loaded it
ESLint found the same plugin at two different file paths and will not pick one.
3 causes, each with a fix