# valid-expect-in-promise

Rule `vitest/valid-expect-in-promise`. Require promises that have expectations in their chain to be valid

- Source: vitest
- Technologies: Testing
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 5.9M weekly downloads of presets that enable it
- Trend: +61.5% last quarter
- Rank: #1403 by reach, #704 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `vitest/valid-expect-in-promise` | yes | no | package `@vitest/eslint-plugin` | [docs](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/valid-expect-in-promise.md) |
| Oxlint | `vitest/valid-expect-in-promise` | no | no | plugin `vitest`, category correctness | [docs](https://oxc.rs/docs/guide/usage/linter/rules/vitest/valid-expect-in-promise.html) |

## Code examples

### Correct: the rule accepts this

```js
test('promise test', async () => {
  something().then((value) => {
    expect(value).toBe('red')
  })
})

test('promises test', () => {
  const onePromise = something().then((value) => {
    expect(value).toBe('red')
  })
  const twoPromise = something().then((value) => {
    expect(value).toBe('blue')
  })

  return Promise.any([onePromise, twoPromise])
})
```

```js
test('promise test', async () => {
  await something().then((value) => {
    expect(value).toBe('red')
  })
})

test('promises test', () => {
  const onePromise = something().then((value) => {
    expect(value).toBe('red')
  })
  const twoPromise = something().then((value) => {
    expect(value).toBe('blue')
  })

  return Promise.all([onePromise, twoPromise])
})
```

Examples from the ESLint documentation.

## Enable it

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

```js
import vitest from "@vitest/eslint-plugin";

export default [
  {
    plugins: { vitest },
    rules: {
      "vitest/valid-expect-in-promise": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "vitest"
  ],
  "rules": {
    "vitest/valid-expect-in-promise": "error"
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Vitest recommended](https://lintradar.dev/presets/vitest-recommended.md) | ESLint | `@vitest/eslint-plugin` | 17 | 5.9M | +61.5% |

## Related rules

- [jest/valid-expect-in-promise](https://lintradar.dev/rules/jest/valid-expect-in-promise.md): Require promises that have expectations in their chain to be valid
- [vitest/valid-expect](https://lintradar.dev/rules/vitest/valid-expect.md): Enforce valid `expect()` usage
- [vitest/valid-describe-callback](https://lintradar.dev/rules/vitest/valid-describe-callback.md): Enforce valid describe callback
- [vitest/require-local-test-context-for-concurrent-snapshots](https://lintradar.dev/rules/vitest/require-local-test-context-for-concurrent-snapshots.md): Require local Test Context for concurrent snapshot tests
- [vitest/prefer-called-exactly-once-with](https://lintradar.dev/rules/vitest/prefer-called-exactly-once-with.md): Prefer `toHaveBeenCalledExactlyOnceWith` over `toHaveBeenCalledOnce` and `toHaveBeenCalledWith`
- [vitest/no-unneeded-async-expect-function](https://lintradar.dev/rules/vitest/no-unneeded-async-expect-function.md): Disallow unnecessary async function wrapper for expected promises

---

Web page: https://lintradar.dev/rules/vitest/valid-expect-in-promise. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
