# prefer-to-have-been-called

Rule `jest/prefer-to-have-been-called`. Suggest using `toHaveBeenCalled`

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

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `jest/prefer-to-have-been-called` | 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.md) |
| Oxlint | `jest/prefer-to-have-been-called` | no | safe | plugin `jest`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/jest/prefer-to-have-been-called.html) |
| Biome | `nursery/useExpectToHaveBeenCalled` | no | safe | group nursery, since 2.6.8 | [docs](https://biomejs.dev/linter/rules/use-expect-to-have-been-called/) |

## Code examples

### Incorrect: the rule reports this

```js
expect(mock).toHaveBeenCalledTimes(0);
expect(mock).toBeCalledTimes(0);
expect(mock).not.toHaveBeenCalledTimes(0);
```

### Correct: the rule accepts this

```js
expect(mock).not.toHaveBeenCalled();
expect(mock).toHaveBeenCalled();
expect(mock).toHaveBeenCalledTimes(1);
```

Examples from the Oxlint 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": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

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

### Biome: `biome.json`

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

## Related rules

- [jest/prefer-strict-equal](https://lintradar.dev/rules/jest/prefer-strict-equal.md): Suggest using `toStrictEqual()`
- [jest/prefer-to-have-been-called-times](https://lintradar.dev/rules/jest/prefer-to-have-been-called-times.md): Suggest using `toHaveBeenCalledTimes()`
- [jest/prefer-spy-on](https://lintradar.dev/rules/jest/prefer-spy-on.md): Suggest using `jest.spyOn()`
- [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-lowercase-title](https://lintradar.dev/rules/jest/prefer-lowercase-title.md): Enforce lowercase test names
- [jest/prefer-importing-jest-globals](https://lintradar.dev/rules/jest/prefer-importing-jest-globals.md): Prefer importing Jest globals

---

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