---
title: "vitest/no-alias-methods"
description: "Disallow matcher aliases such as `toBeCalled` in favor of `toHaveBeenCalled`"
# Generated by src/codegen/lint-rule-docs.ts. Do not edit below this line.
plugin: "vitest"
aliases: []
kind: "suggestion"
category: "style"
default: "off"
fixable: "yes"
typeAware: false
deprecated: false
---

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.

{/* 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]
"vitest/no-alias-methods" = "error" # or "warn"
```

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

## Examples

Reported:

{/* bad */}
```ts
import { expect, test, vi } from "vitest";

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

Not reported:

{/* good */}
```ts
import { expect, test, vi } from "vitest";

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

The full list:

| Reported | Write instead |
| --- | --- |
| `toBeCalled` | `toHaveBeenCalled` |
| `toBeCalledTimes` | `toHaveBeenCalledTimes` |
| `toBeCalledWith` | `toHaveBeenCalledWith` |
| `lastCalledWith` | `toHaveBeenLastCalledWith` |
| `nthCalledWith` | `toHaveBeenNthCalledWith` |
| `toReturn` | `toHaveReturned` |
| `toReturnTimes` | `toHaveReturnedTimes` |
| `toReturnWith` | `toHaveReturnedWith` |
| `lastReturnedWith` | `toHaveLastReturnedWith` |
| `nthReturnedWith` | `toHaveNthReturnedWith` |
| `toThrowError` | `toThrow` |
