> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# prefer-called-with

[Added in v0.6.0](https://github.com/web-infra-dev/rslint/releases/tag/v0.6.0)
## Configuration

| Preset                   | Configured Value |
| ------------------------ | ---------------- |
| ✅ jestPlugin.configs.all | `"error"`        |


```ts title=rslint.config.ts
import { defineConfig, jestPlugin } from '@rslint/core';

export default defineConfig([
  jestPlugin.configs.recommended,
  {
    rules: {
      'jest/prefer-called-with': 'error',
    },
  },
]);
```

## Rule Details

The `toHaveBeenCalled()` and `toBeCalled()` matchers assert that a mock function
has been called one or more times, without checking the arguments passed. The
assertion is stronger when arguments are also validated using
`toHaveBeenCalledWith()` or `toBeCalledWith()`. When some arguments are difficult
to check, using generic matchers such as `expect.anything()` at least enforces the
number and position of arguments.

Examples of **incorrect** code for this rule:

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

expect(someFunction).toHaveBeenCalled();
```

Examples of **correct** code for this rule:

```js
expect(noArgsFunction).toHaveBeenCalledWith();

expect(roughArgsFunction).toHaveBeenCalledWith(
  expect.anything(),
  expect.any(Date),
);

expect(anyArgsFunction).toHaveBeenCalledTimes(1);

expect(uncalledFunction).not.toHaveBeenCalled();
```

## Original Documentation

- [eslint-plugin-jest: prefer-called-with](https://github.com/jest-community/eslint-plugin-jest/blob/v29.16.0/docs/rules/prefer-called-with.md)
- [Source code](https://github.com/jest-community/eslint-plugin-jest/blob/v29.16.0/src/rules/prefer-called-with.ts)
