# prefer-to-have-been-called-times

Rule `jest/prefer-to-have-been-called-times`. Suggest using `toHaveBeenCalledTimes()`

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

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `jest/prefer-to-have-been-called-times` | no | safe | package `eslint-plugin-jest` | [docs](https://github.com/jest-community/eslint-plugin-jest/blob/v29.17.2/docs/rules/prefer-to-have-been-called-times.md) |
| Oxlint | `jest/prefer-to-have-been-called-times` | no | safe | plugin `jest`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/jest/prefer-to-have-been-called-times.html) |
| Biome | `nursery/useExpectToHaveBeenCalledTimes` | no | unsafe | group nursery, since 2.6.8 | [docs](https://biomejs.dev/linter/rules/use-expect-to-have-been-called-times/) |

## Code examples

### Incorrect: the rule reports this

```js
expect(onSave.mock.calls).toHaveLength(1);
```

```js
expect(onSave.mock.calls).not.toHaveLength(0);
```

### Correct: the rule accepts this

```js
expect(onSave).toHaveBeenCalledTimes(1);
expect(onSave).not.toHaveBeenCalledTimes(0);
expect(onSave.mock.calls[0]).toHaveLength(2);
```

Examples from the Biome documentation.

## Enable it

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

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

export default [
  {
    plugins: { jest },
    rules: {
      "jest/prefer-to-have-been-called-times": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "jest"
  ],
  "rules": {
    "jest/prefer-to-have-been-called-times": "error"
  }
}
```

### Biome: `biome.json`

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

## Related rules

- [vitest/prefer-to-have-been-called-times](https://lintradar.dev/rules/vitest/prefer-to-have-been-called-times.md): Suggest using `toHaveBeenCalledTimes()`
- [jest/prefer-to-have-been-called](https://lintradar.dev/rules/jest/prefer-to-have-been-called.md): Suggest using `toHaveBeenCalled`
- [jest/require-top-level-describe](https://lintradar.dev/rules/jest/require-top-level-describe.md): Require test cases and hooks to be inside a `describe` block
- [jest/prefer-strict-equal](https://lintradar.dev/rules/jest/prefer-strict-equal.md): Suggest using `toStrictEqual()`
- [jest/prefer-spy-on](https://lintradar.dev/rules/jest/prefer-spy-on.md): Suggest using `jest.spyOn()`
- [jest/prefer-lowercase-title](https://lintradar.dev/rules/jest/prefer-lowercase-title.md): Enforce lowercase test names

---

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