# no-conditional-expect

Rule `vitest/no-conditional-expect`. Disallow conditional expects

- 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: #1390 by reach, #691 by growth

## Linters

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

## Code examples

### Incorrect: the rule reports this

```ts
test('foo', () => {
  if (false) {
    expect(1).toBe(1)
  }
})

test.for([null, { bar: 'baz' }])('quux', (value) => {
  const expected = value === null ? expected : expect.stringContaining(expected)
  expect(actual).toEqual(expected)
})
```

### Correct: the rule accepts this

```ts
test('foo', () => {
  expect(1).toBe(1)
})

test.for([null, expect.objectContaining({ bar: 'baz' })])(
  'quux',
  (expected) => {
    expect(actual).toEqual(expected)
  },
)
```

Examples from the ESLint documentation.

## Enable it

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

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

export default [
  {
    plugins: { vitest },
    rules: {
      "vitest/no-conditional-expect": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "vitest"
  ],
  "rules": {
    "vitest/no-conditional-expect": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "suspicious": {
        "noConditionalExpect": "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/no-conditional-expect](https://lintradar.dev/rules/jest/no-conditional-expect.md): Disallow calling `expect` conditionally
- [vitest/expect-expect](https://lintradar.dev/rules/vitest/expect-expect.md): Enforce having expectation in test body
- [vitest/no-disabled-tests](https://lintradar.dev/rules/vitest/no-disabled-tests.md): Disallow disabled tests
- [vitest/no-focused-tests](https://lintradar.dev/rules/vitest/no-focused-tests.md): Disallow focused tests
- [vitest/no-standalone-expect](https://lintradar.dev/rules/vitest/no-standalone-expect.md): Disallow using `expect` outside of `it` or `test` blocks
- [vitest/valid-title](https://lintradar.dev/rules/vitest/valid-title.md): Enforce valid titles

---

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