# prefer-expect-assertions

Rule `vitest/prefer-expect-assertions`. Enforce using expect assertions instead of callbacks

- Source: vitest
- 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: #1794 by reach

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
test('no assertions', () => {
  // ...
})

test('assertions not first', () => {
  expect(true).toBe(true)
  // ...
})
```

### Correct: the rule accepts this

```js
test('assertions first', () => {
  expect.assertions(1)
  // ...
})

test('assertions first', () => {
  expect.hasAssertions()
  // ...
})
```

Examples from the ESLint documentation.

## Enable it

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

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

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

### Oxlint: `.oxlintrc.json`

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

## Related rules

- [jest/prefer-expect-assertions](https://lintradar.dev/rules/jest/prefer-expect-assertions.md): Suggest using `expect.assertions()` OR `expect.hasAssertions()`
- [vitest/prefer-each](https://lintradar.dev/rules/vitest/prefer-each.md): Enforce using `each` rather than manual loops
- [vitest/prefer-expect-resolves](https://lintradar.dev/rules/vitest/prefer-expect-resolves.md): Enforce using `expect().resolves` over `expect(await ...)` syntax
- [vitest/prefer-comparison-matcher](https://lintradar.dev/rules/vitest/prefer-comparison-matcher.md): Enforce using the built-in comparison matchers
- [vitest/prefer-expect-type-of](https://lintradar.dev/rules/vitest/prefer-expect-type-of.md): Enforce using `expect(...).toBeTypeOf(...)` instead of `expect(typeof ...).toBe(...)`
- [vitest/prefer-called-once](https://lintradar.dev/rules/vitest/prefer-called-once.md): Enforce using `toBeCalledOnce()` or `toHaveBeenCalledOnce()`

---

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