vitest/no-alias-methods

Disallow matcher aliases such as toBeCalled in favor of toHaveBeenCalled

fixable

Some matchers have two names. For example, toBeCalled is the same matcher as toHaveBeenCalled. If a project uses both, a search for one name misses the tests that use the other.

--fix renames the matcher.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"vitest/no-alias-methods" = "error" # or "warn"

Examples#

example.ts1 problem
import { expect, test, vi } from "vitest";

test("saves the draft", () => {
  const save = vi.fn();
  save("draft");
  expect(save).toBeCalledWith("draft");
});
example.tsNo problems
import { expect, test, vi } from "vitest";

test("saves the draft", () => {
  const save = vi.fn();
  save("draft");
  expect(save).toHaveBeenCalledWith("draft");
});

The full list:

ReportedWrite instead
toBeCalledtoHaveBeenCalled
toBeCalledTimestoHaveBeenCalledTimes
toBeCalledWithtoHaveBeenCalledWith
lastCalledWithtoHaveBeenLastCalledWith
nthCalledWithtoHaveBeenNthCalledWith
toReturntoHaveReturned
toReturnTimestoHaveReturnedTimes
toReturnWithtoHaveReturnedWith
lastReturnedWithtoHaveLastReturnedWith
nthReturnedWithtoHaveNthReturnedWith
toThrowErrortoThrow