# no-untyped-mock-factory

Rule `jest/no-untyped-mock-factory`. Disallow using `jest.mock()` factories without an explicit type parameter

- Source: jest
- Technologies: Testing
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #1744 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `jest/no-untyped-mock-factory` | no | safe | package `eslint-plugin-jest` | [docs](https://github.com/jest-community/eslint-plugin-jest/blob/v29.17.2/docs/rules/no-untyped-mock-factory.md) |
| Oxlint | `jest/no-untyped-mock-factory` | no | safe | plugin `jest`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/jest/no-untyped-mock-factory.html) |

## Code examples

### Incorrect: the rule reports this

```ts
jest.mock('../moduleName', () => {
    return jest.fn(() => 42);
});

jest.mock('./module', () => ({
    ...jest.requireActual('./module'),
    foo: jest.fn(),
}));

jest.mock('random-num', () => {
    return jest.fn(() => 42);
});
```

### Correct: the rule accepts this

```ts
// Uses typeof import()
jest.mock<typeof import('../moduleName')>('../moduleName', () => {
    return jest.fn(() => 42);
});

jest.mock<typeof import('./module')>('./module', () => ({
    ...jest.requireActual('./module'),
    foo: jest.fn(),
}));

// Uses custom type
jest.mock<() => number>('random-num', () => {
    return jest.fn(() => 42);
});

// No factory
jest.mock('random-num');

// Virtual mock
jest.mock(
    '../moduleName',
    () => {
        return jest.fn(() => 42);
    },
    { virtual: true },
);
```

Examples from the Oxlint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import jest from "eslint-plugin-jest";

export default [
  {
    plugins: { jest },
    rules: {
      "jest/no-untyped-mock-factory": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "jest"
  ],
  "rules": {
    "jest/no-untyped-mock-factory": "error"
  }
}
```

## Related rules

- [jest/no-unneeded-async-expect-function](https://lintradar.dev/rules/jest/no-unneeded-async-expect-function.md): Disallow unnecessary async function wrapper for expected promises
- [jest/padding-around-after-all-blocks](https://lintradar.dev/rules/jest/padding-around-after-all-blocks.md): Enforce padding around `afterAll` blocks
- [jest/no-restricted-matchers](https://lintradar.dev/rules/jest/no-restricted-matchers.md): Disallow specific matchers & modifiers
- [jest/padding-around-after-each-blocks](https://lintradar.dev/rules/jest/padding-around-after-each-blocks.md): Enforce padding around `afterEach` blocks
- [jest/no-restricted-jest-methods](https://lintradar.dev/rules/jest/no-restricted-jest-methods.md): Disallow specific `jest.` methods
- [jest/padding-around-all](https://lintradar.dev/rules/jest/padding-around-all.md): Enforce padding around Jest functions

---

Web page: https://lintradar.dev/rules/jest/no-untyped-mock-factory. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
