> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# prefer-to-have-been-called

[Added in v0.6.0](https://github.com/web-infra-dev/rslint/releases/tag/v0.6.0)
## Configuration

| Preset                   | Configured Value |
| ------------------------ | ---------------- |
| ✅ jestPlugin.configs.all | `"error"`        |


```ts title=rslint.config.ts
import { defineConfig, jestPlugin } from '@rslint/core';

export default defineConfig([
  jestPlugin.configs.recommended,
  {
    rules: {
      'jest/prefer-to-have-been-called': 'error',
    },
  },
]);
```

## Rule Details

In order to have a better failure message, `toHaveBeenCalled()` and
`not.toHaveBeenCalled()` should be used when asserting that a mock has or has
not been called.

This rule triggers a warning if `toHaveBeenCalledTimes` or `toBeCalledTimes` is
used to assert that a mock has or has not been called zero times.

Examples of **incorrect** code for this rule:

```js
expect(method).toHaveBeenCalledTimes(0);

expect(method).not.toHaveBeenCalledTimes(0);
```

Examples of **correct** code for this rule:

```js
expect(method).not.toHaveBeenCalled();

expect(method).toHaveBeenCalled();
```

## Original Documentation

- [eslint-plugin-jest: prefer-to-have-been-called](https://github.com/jest-community/eslint-plugin-jest/blob/v29.16.0/docs/rules/prefer-to-have-been-called.md)
- [Source code](https://github.com/jest-community/eslint-plugin-jest/blob/v29.16.0/src/rules/prefer-to-have-been-called.ts)
