jest/no-untyped-mock-factory
Added in v0.9.4Configuration
Require a type argument on jest.mock and jest.doMock, or an explicit return type on their inline factories, so TypeScript can check the mocked module shape.
Rule Details
This rule checks calls with exactly two arguments. Calls with no factory, a third argument such as { virtual: true }, an explicit type argument (including any), or an inline factory return annotation are exempt. A separately declared factory still needs a type argument on the mock call.
Enable this rule only for TypeScript files: its fixes insert TypeScript syntax. It does not require type information and does not check whether the annotation matches the actual module.
Incorrect
Correct
Autofix
Adds <typeof import('./module')> when the first argument is a quoted string and the callee can accept exactly one type argument, preserving its quotes and escapes. Other module expressions, type assertions that cannot be resolved and CommonJS require() bindings are reported without a fix.
Differences from ESLint
For parenthesized calls such as (jest.mock)(path, factory), the type argument is inserted after the closing parenthesis, directly on the call.
For optional calls such as jest.mock?.('./user-service', factory), the type argument is inserted after ?. directly on the optional call.