# valid-expect

Rule `jest/valid-expect`. Enforce valid `expect()` usage

- Source: jest
- Technologies: Testing
- Kind: correctness
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 18M weekly downloads of presets that enable it
- Trend: +9.8% last quarter
- Rank: #636 by reach, #1478 by growth

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
// alwaysAwait: true
test('test1', async () => {
  await expect(Promise.resolve(2)).resolves.toBeDefined();
  return expect(Promise.resolve(1)).resolves.toBe(1); // `return` statement will trigger a warning
});
```

### Correct: the rule accepts this

```js
// alwaysAwait: true
test('test1', async () => {
  await expect(Promise.resolve(2)).resolves.toBeDefined();
  await expect(Promise.resolve(1)).resolves.toBe(1);
});

test('test2', () => expect(Promise.resolve(2)).resolves.toBe(2));
```

Examples from the ESLint documentation.

## Enable it

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

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

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

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "jest"
  ],
  "rules": {
    "jest/valid-expect": "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% |
| [React Native](https://lintradar.dev/presets/react-native.md) | ESLint | `@react-native/eslint-config` | 79 | 1.2M | +5.8% |

## Related rules

- [vitest/valid-expect](https://lintradar.dev/rules/vitest/valid-expect.md): Enforce valid `expect()` usage
- [jest/no-disabled-tests](https://lintradar.dev/rules/jest/no-disabled-tests.md): Disallow disabled tests
- [jest/expect-expect](https://lintradar.dev/rules/jest/expect-expect.md): Enforce assertion to be made in a test body
- [jest/no-conditional-expect](https://lintradar.dev/rules/jest/no-conditional-expect.md): Disallow calling `expect` conditionally
- [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

---

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