# bun:test/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-suggestions` renames the matcher and leaves the parentheses empty. Fill in the arguments you expect, because `toHaveBeenCalledWith()` only passes for a call without arguments. That's why `--fix` doesn't rename it.

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

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

## Examples

Reported:

{/* bad */}
```ts
import { expect, mock, test } from "bun:test";

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

Not reported:

{/* good */}
```ts
import { expect, mock, test } from "bun:test";

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

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