bun:test/prefer-to-have-been-called

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

fixable

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.

Configure#

Off by default. To turn it on:

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

Examples#

example.ts2 problems
import { expect, mock, test } from "bun:test";

test("only notifies on failure", () => {
  const onError = mock();
  const onDone = mock();
  run(task, { onError, onDone });
  expect(onError).toHaveBeenCalledTimes(0);
  expect(onDone).not.toHaveBeenCalledTimes(0);
});
example.tsNo problems
import { expect, mock, test } from "bun:test";

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