jest/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]
"jest/prefer-to-have-been-called" = "error" # or "warn"Examples#
example.ts2 problems
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)Prefer toHaveBeenCalled() over toHaveBeenCalledTimes(0);
expect(onDone).not.toHaveBeenCalledTimes(0)Prefer toHaveBeenCalled() over toHaveBeenCalledTimes(0);
});example.tsNo problems
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);
});