> 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.

# valid-expect

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

| Preset                             | Configured Value |
| ---------------------------------- | ---------------- |
| ✅ rstestPlugin.configs.all         | `"warn"`         |
| ✅ rstestPlugin.configs.recommended | `"error"`        |


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

export default defineConfig([
  rstestPlugin.configs.recommended,
  {
    rules: {
      'rstest/valid-expect': 'error',
    },
  },
]);
```

## Rule Details

Validates Rstest `expect` calls: they need the required arguments and a matcher, and asynchronous assertions must be awaited or returned so failures are not lost.

Rstest supports a message as the second `expect` argument and Chai-style property assertions; both are accepted by the rule.

## Incorrect

```ts
expect(user);

test('loads a user', async () => {
  expect(loadUser()).resolves.toMatchObject({ name: 'Ada' });
});
```

## Correct

```ts
expect(user).toMatchObject({ name: 'Ada' });

test('loads a user', async () => {
  await expect(loadUser()).resolves.toMatchObject({ name: 'Ada' });
});
```

## Options

```json
{
  "rstest/valid-expect": [
    "error",
    {
      "alwaysAwait": true,
      "asyncMatchers": ["toReject", "toResolve", "toSettle"],
      "maxArgs": 2
    }
  ]
}
```

| Option          | Type       | Default                     | Description                                                                  |
| --------------- | ---------- | --------------------------- | ---------------------------------------------------------------------------- |
| `alwaysAwait`   | `boolean`  | `false`                     | Require async assertions to be awaited instead of allowing `return`.         |
| `asyncMatchers` | `string[]` | `["toReject", "toResolve"]` | Matcher names treated as asynchronous. Setting it replaces the default list. |
| `minArgs`       | `number`   | `1`                         | Minimum number of arguments for `expect`.                                    |
| `maxArgs`       | `number`   | `1`                         | Maximum number of arguments for `expect`.                                    |

## Autofix

An async assertion that is neither awaited nor returned is fixed by adding `await`, and by marking the enclosing function `async` when it is not already. Argument-count and matcher problems are reported without a fix.
