# prefer-expect-assertions

Rule `jest/prefer-expect-assertions`. Suggest using `expect.assertions()` OR `expect.hasAssertions()`

- Source: jest
- Technologies: Testing
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #1756 by reach

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
describe('getNumbers', () => {
  it('only returns numbers that are greater than zero', () => {
    const numbers = getNumbers();

    for (const number in numbers) {
      expect(number).toBeGreaterThan(0);
    }
  });
});
```

```js
describe('getNumbers', () => {
  it('only returns numbers that are greater than zero', () => {
    const numbers = getNumbers();

    getNumbers().forEach(number => {
      expect(number).toBeGreaterThan(0);
    });
  });
});

describe('/users', () => {
  it.each([1, 2, 3])('returns ok', id => {
    client.get(`/users/${id}`, response => {
      expect(response.status).toBe(200);
    });
  });
});
```

### Correct: the rule accepts this

```js
test('my test', () => {
  expect.assertions('1');
  expect(someThing()).toEqual('foo');
});
```

```js
test('my test', () => {
  expect.assertions('1');
  expect(someThing()).toEqual('foo');
});

test('my test', () => {
  expect(someThing()).toEqual('foo');
});
```

```js
test('my test', () => {
  expect.assertions(1);
  expect(someThing()).toEqual('foo');
});

test('my test', () => {
  expect.hasAssertions();
  expect(someThing()).toEqual('foo');
});
```

Examples from the ESLint documentation.

## Enable it

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

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

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

### Oxlint: `.oxlintrc.json`

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

## Related rules

- [vitest/prefer-expect-assertions](https://lintradar.dev/rules/vitest/prefer-expect-assertions.md): Enforce using expect assertions instead of callbacks
- [jest/prefer-ending-with-an-expect](https://lintradar.dev/rules/jest/prefer-ending-with-an-expect.md): Prefer having the last statement in a test be an assertion
- [jest/prefer-expect-resolves](https://lintradar.dev/rules/jest/prefer-expect-resolves.md): Prefer `await expect(...).resolves` over `expect(await ...)` syntax
- [jest/prefer-each](https://lintradar.dev/rules/jest/prefer-each.md): Prefer using `.each` rather than manual loops
- [jest/prefer-jest-mocked](https://lintradar.dev/rules/jest/prefer-jest-mocked.md): Prefer `jest.mocked()` over `fn as jest.Mock`
- [jest/prefer-comparison-matcher](https://lintradar.dev/rules/jest/prefer-comparison-matcher.md): Suggest using the built-in comparison matchers

---

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