> 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-times

[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-times': 'error',
    },
  },
]);
```

## Rule Details

In order to have a better failure message, `toHaveBeenCalledTimes()` should be
used instead of directly checking the length of `mock.calls`.

This rule triggers a warning if `toHaveLength` is used to assert the number of
times a mock has been called.

This rule is often used together with
[`prefer-to-have-length`](https://rslint.rs/rules/jest/prefer-to-have-length.md).

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

```js
expect(someFunction.mock.calls).toHaveLength(1);
expect(someFunction.mock.calls).toHaveLength(0);

expect(someFunction.mock.calls).not.toHaveLength(1);
```

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

```js
expect(someFunction).toHaveBeenCalledTimes(1);
expect(someFunction).toHaveBeenCalledTimes(0);

expect(someFunction).not.toHaveBeenCalledTimes(0);

expect(uncalledFunction).not.toBeCalled();

expect(method.mock.calls[0][0]).toStrictEqual(value);
```

## Original Documentation

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