# no-conditional-in-test

Rule `jest/no-conditional-in-test`. Disallow conditional logic in tests

- Source: jest
- Technologies: Testing
- Kind: suspicious
- Needs type information: no
- Autofix: no
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #1738 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `jest/no-conditional-in-test` | no | no | package `eslint-plugin-jest` | [docs](https://github.com/jest-community/eslint-plugin-jest/blob/v29.17.2/docs/rules/no-conditional-in-test.md) |
| Oxlint | `jest/no-conditional-in-test` | no | no | plugin `jest`, category pedantic | [docs](https://oxc.rs/docs/guide/usage/linter/rules/jest/no-conditional-in-test.html) |

## Code examples

### Incorrect: the rule reports this

```js
it('foo', () => {
  if (true) {
    doTheThing();
  }
});

it('bar', () => {
  switch (mode) {
    case 'none':
      generateNone();
    case 'single':
      generateOne();
    case 'multiple':
      generateMany();
  }

  expect(fixtures.length).toBeGreaterThan(-1);
});

it('qux', async () => {
  const promiseValue = () => {
    return something instanceof Promise
      ? something
      : Promise.resolve(something);
  };

  await expect(promiseValue()).resolves.toBe(1);
});
```

### Correct: the rule accepts this

```js
describe('my tests', () => {
  if (true) {
    it('foo', () => {
      doTheThing();
    });
  }
});

beforeEach(() => {
  switch (mode) {
    case 'none':
      generateNone();
    case 'single':
      generateOne();
    case 'multiple':
      generateMany();
  }
});

it('bar', () => {
  expect(fixtures.length).toBeGreaterThan(-1);
});

const promiseValue = something => {
  return something instanceof Promise ? something : Promise.resolve(something);
};

it('qux', async () => {
  await expect(promiseValue()).resolves.toBe(1);
});
```

Examples from the ESLint documentation.

## Enable it

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

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

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

### Oxlint: `.oxlintrc.json`

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

## Related rules

- [vitest/no-conditional-in-test](https://lintradar.dev/rules/vitest/no-conditional-in-test.md): Disallow conditional tests
- [jest/max-expects](https://lintradar.dev/rules/jest/max-expects.md): Enforces a maximum number assertion calls in a test body
- [jest/no-confusing-set-timeout](https://lintradar.dev/rules/jest/no-confusing-set-timeout.md): Disallow confusing usages of jest.setTimeout
- [jest/no-large-snapshots](https://lintradar.dev/rules/jest/no-large-snapshots.md): Disallow large snapshots
- [jest/no-restricted-jest-methods](https://lintradar.dev/rules/jest/no-restricted-jest-methods.md): Disallow specific `jest.` methods
- [jest/no-restricted-matchers](https://lintradar.dev/rules/jest/no-restricted-matchers.md): Disallow specific matchers & modifiers

---

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