# no-conditional-expect

Rule `jest/no-conditional-expect`. Disallow calling `expect` conditionally

- Source: jest
- Technologies: Testing
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 16.7M weekly downloads of presets that enable it
- Trend: +10.1% last quarter
- Rank: #654 by reach, #1461 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `jest/no-conditional-expect` | yes | no | package `eslint-plugin-jest` | [docs](https://github.com/jest-community/eslint-plugin-jest/blob/v29.17.2/docs/rules/no-conditional-expect.md) |
| Oxlint | `jest/no-conditional-expect` | no | no | plugin `jest`, category correctness | [docs](https://oxc.rs/docs/guide/usage/linter/rules/jest/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

```js
test("conditional expect", async ({ page }) => {
    if (someCondition) {
        await expect(page).toHaveTitle("Title");
    }
});
```

```js
test("ternary expect", async ({ page }) => {
    someCondition ? await expect(page).toHaveTitle("Title") : null;
});
```

```js
test("catch expect", async ({ page }) => {
    try {
        await page.click("button");
    } catch (e) {
        await expect(page).toHaveTitle("Title");
    }
});
```

### Correct: the rule accepts this

```js
test("unconditional expect", async ({ page }) => {
    await expect(page).toHaveTitle("Title");
});
```

```js
test("skip based on condition", async ({ page }) => {
    test.skip(someCondition, "Reason to skip");
    await expect(page).toHaveTitle("Title");
});
```

Examples from the Biome documentation.

## Enable it

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

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

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

### Oxlint: `.oxlintrc.json`

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

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "suspicious": {
        "noConditionalExpect": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Jest recommended](https://lintradar.dev/presets/jest-recommended.md) | ESLint | `eslint-plugin-jest` | 19 | 16.7M | +10.1% |

## Related rules

- [vitest/no-conditional-expect](https://lintradar.dev/rules/vitest/no-conditional-expect.md): Disallow conditional expects
- [jest/expect-expect](https://lintradar.dev/rules/jest/expect-expect.md): Enforce assertion to be made in a test body
- [jest/no-done-callback](https://lintradar.dev/rules/jest/no-done-callback.md): Disallow using a callback in asynchronous tests and hooks
- [jest/no-jasmine-globals](https://lintradar.dev/rules/jest/no-jasmine-globals.md): Disallow Jasmine globals
- [jest/no-standalone-expect](https://lintradar.dev/rules/jest/no-standalone-expect.md): Disallow using `expect` outside of `it` or `test` blocks
- [jest/valid-title](https://lintradar.dev/rules/jest/valid-title.md): Enforce valid titles

---

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