# prefer-called-with

Rule `jest/prefer-called-with`. Suggest using `toHaveBeenCalledWith()`

- Source: jest
- Technologies: Testing
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #1662 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `jest/prefer-called-with` | no | no | package `eslint-plugin-jest` | [docs](https://github.com/jest-community/eslint-plugin-jest/blob/v29.17.2/docs/rules/prefer-called-with.md) |
| Oxlint | `jest/prefer-called-with` | no | safe | plugin `jest`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/jest/prefer-called-with.html) |
| Biome | `nursery/useCalledWith` | no | no | group nursery, since 2.6.8 | [docs](https://biomejs.dev/linter/rules/use-called-with/) |

## Code examples

### Incorrect: the rule reports this

```js
expect(sendEmail).toHaveBeenCalled();
```

```js
expect(sendEmail).toBeCalled();
```

```js
expect(sendEmail).toHaveBeenCalledOnce();
```

### Correct: the rule accepts this

```js
expect(sendEmail).toHaveBeenCalledWith("user@example.com", expect.anything());
expect(sendEmail).toHaveBeenCalledExactlyOnceWith("user@example.com");
expect(refresh).toHaveBeenCalledWith();
expect(sendEmail).toHaveBeenCalledTimes(1);
expect(sendEmail).not.toHaveBeenCalled();
```

Examples from the Biome documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import jest from "eslint-plugin-jest";

export default [
  {
    plugins: { jest },
    rules: {
      "jest/prefer-called-with": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "jest"
  ],
  "rules": {
    "jest/prefer-called-with": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "useCalledWith": "error"
      }
    }
  }
}
```

## Related rules

- [vitest/prefer-called-with](https://lintradar.dev/rules/vitest/prefer-called-with.md): Enforce using `toBeCalledWith()` or `toHaveBeenCalledWith()`
- [jest/no-hooks](https://lintradar.dev/rules/jest/no-hooks.md): Disallow setup and teardown hooks
- [jest/prefer-equality-matcher](https://lintradar.dev/rules/jest/prefer-equality-matcher.md): Suggest using the built-in equality matchers
- [jest/max-nested-describe](https://lintradar.dev/rules/jest/max-nested-describe.md): Enforces a maximum depth to nested describe calls
- [jest/prefer-hooks-in-order](https://lintradar.dev/rules/jest/prefer-hooks-in-order.md): Prefer having hooks in a consistent order
- [jest/consistent-test-it](https://lintradar.dev/rules/jest/consistent-test-it.md): Enforce `test` and `it` usage conventions

---

Web page: https://lintradar.dev/rules/jest/prefer-called-with. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
