# prefer-called-times

Rule `vitest/prefer-called-times`. Enforce using `toBeCalledTimes(1)` or `toHaveBeenCalledTimes(1)`

- 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: #1686 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `vitest/prefer-called-times` | no | safe | package `@vitest/eslint-plugin` | [docs](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-called-times.md) |
| Oxlint | `vitest/prefer-called-times` | no | safe | plugin `vitest`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/vitest/prefer-called-times.html) |
| Biome | `nursery/noExpectToHaveBeenCalledOnce` | no | safe | group nursery, since 2.6.9 | [docs](https://biomejs.dev/linter/rules/no-expect-to-have-been-called-once/) |

## Code examples

### Incorrect: the rule reports this

```ts
test('foo', () => {
  const mock = vi.fn()
  mock('foo')
  expect(mock).toBeCalledOnce()
  expect(mock).toHaveBeenCalledOnce()
})
```

### Correct: the rule accepts this

```ts
test('foo', () => {
  const mock = vi.fn()
  mock('foo')
  expect(mock).toBeCalledTimes(1)
  expect(mock).toHaveBeenCalledTimes(1)
})
```

Examples from the ESLint documentation.

## Enable it

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

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

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

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "vitest"
  ],
  "rules": {
    "vitest/prefer-called-times": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "noExpectToHaveBeenCalledOnce": "error"
      }
    }
  }
}
```

## Related rules

- [vitest/no-test-return-statement](https://lintradar.dev/rules/vitest/no-test-return-statement.md): Disallow return statements in tests
- [vitest/prefer-called-with](https://lintradar.dev/rules/vitest/prefer-called-with.md): Enforce using `toBeCalledWith()` or `toHaveBeenCalledWith()`
- [vitest/no-hooks](https://lintradar.dev/rules/vitest/no-hooks.md): Disallow setup and teardown hooks
- [vitest/prefer-describe-function-title](https://lintradar.dev/rules/vitest/prefer-describe-function-title.md): Enforce using a function as a describe title over an equivalent string
- [vitest/no-duplicate-hooks](https://lintradar.dev/rules/vitest/no-duplicate-hooks.md): Disallow duplicate hooks and teardown hooks
- [vitest/prefer-equality-matcher](https://lintradar.dev/rules/vitest/prefer-equality-matcher.md): Enforce using the built-in equality matchers

---

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