# vitest/prefer-called-with

> Require `toHaveBeenCalledWith()` instead of `toHaveBeenCalled()`

`toHaveBeenCalled()` passes no matter what the mock was called with, so the test keeps passing when the code starts passing the wrong arguments. `toHaveBeenCalledWith(...)` checks the arguments too. The alias `toBeCalled()` is reported the same way.

`.not.toHaveBeenCalled()` is allowed, because a mock that never ran has no arguments to check.

`--fix` renames the matcher and leaves the parentheses empty. Fill in the arguments you expect, because `toHaveBeenCalledWith()` only passes for a call without arguments.

{/* 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/prefer-called-with" = "error" # or "warn"
```

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

## Examples

Reported:

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

test("sends a welcome email", () => {
  const send = vi.fn();
  register("ada@example.com", send);
  expect(send).toHaveBeenCalled();
});
```

Not reported:

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

test("sends a welcome email", () => {
  const send = vi.fn();
  register("ada@example.com", send);
  expect(send).toHaveBeenCalledWith("ada@example.com", "welcome");
});

test("sends nothing for an invalid address", () => {
  const send = vi.fn();
  register("not an address", send);
  expect(send).not.toHaveBeenCalled();
});
```
