# jest/prefer-to-have-been-called

> Require `not.toHaveBeenCalled()` instead of `toHaveBeenCalledTimes(0)`

`toHaveBeenCalledTimes(0)` means "not called", and `.not.toHaveBeenCalledTimes(0)` is a double negative for "called". `.not.toHaveBeenCalled()` and `toHaveBeenCalled()` say it directly.

The alias `toBeCalledTimes(0)` is reported too. Any other count is fine.

`--fix` rewrites both forms.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"jest/prefer-to-have-been-called" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 2} */}
```ts
import { expect, jest, test } from "@jest/globals";

test("only notifies on failure", () => {
  const onError = jest.fn();
  const onDone = jest.fn();
  run(task, { onError, onDone });
  expect(onError).toHaveBeenCalledTimes(0);
  expect(onDone).not.toHaveBeenCalledTimes(0);
});
```

Not reported:

{/* good */}
```ts
import { expect, jest, test } from "@jest/globals";

test("only notifies on failure", () => {
  const onError = jest.fn();
  const onDone = jest.fn();
  run(task, { onError, onDone });
  expect(onError).not.toHaveBeenCalled();
  expect(onDone).toHaveBeenCalled();
  expect(onDone).toHaveBeenCalledTimes(1);
});
```
