# prefer-vi-mocked

Rule `vitest/prefer-vi-mocked`. Require `vi.mocked()` over `fn as Mock`

- Source: vitest
- 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: #2183 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `vitest/prefer-vi-mocked` | no | safe | package `@vitest/eslint-plugin` | [docs](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-vi-mocked.md) |

## Enable it

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

```js
import vitest from "@vitest/eslint-plugin";

export default [
  {
    plugins: { vitest },
    rules: {
      "vitest/prefer-vi-mocked": "error",
    },
  },
];
```

## Related rules

- [vitest/unbound-method](https://lintradar.dev/rules/vitest/unbound-method.md): Enforce unbound methods are called with their expected scope
- [vitest/warn-todo](https://lintradar.dev/rules/vitest/warn-todo.md): Disallow `.todo` usage
- [vitest/require-to-throw-message](https://lintradar.dev/rules/vitest/require-to-throw-message.md): Require toThrow() to be called with an error message
- [vitest/require-test-timeout](https://lintradar.dev/rules/vitest/require-test-timeout.md): Require tests to declare a timeout
- [vitest/require-mock-type-parameters](https://lintradar.dev/rules/vitest/require-mock-type-parameters.md): Enforce using type parameters with vitest mock functions
- [vitest/require-hook](https://lintradar.dev/rules/vitest/require-hook.md): Require setup and teardown to be within a hook

---

Web page: https://lintradar.dev/rules/vitest/prefer-vi-mocked. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
