# prefer-ending-with-an-expect

Rule `jest/prefer-ending-with-an-expect`. Prefer having the last statement in a test be an assertion

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

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
it('lets me change the selected option', () => {
  const container = render(MySelect, {
    props: { options: [1, 2, 3], selected: 1 },
  });

  expect(container).toBeDefined();
  expect(container.toHTML()).toContain('<option value="1" selected>');

  container.setProp('selected', 2);
});
```

### Correct: the rule accepts this

```js
it('lets me change the selected option', () => {
  const container = render(MySelect, {
    props: { options: [1, 2, 3], selected: 1 },
  });

  expect(container).toBeDefined();
  expect(container.toHTML()).toContain('<option value="1" selected>');

  container.setProp('selected', 2);

  expect(container.toHTML()).not.toContain('<option value="1" selected>');
  expect(container.toHTML()).toContain('<option value="2" selected>');
});
```

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-ending-with-an-expect": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

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

## Related rules

- [jest/prefer-each](https://lintradar.dev/rules/jest/prefer-each.md): Prefer using `.each` rather than manual loops
- [jest/prefer-expect-assertions](https://lintradar.dev/rules/jest/prefer-expect-assertions.md): Suggest using `expect.assertions()` OR `expect.hasAssertions()`
- [jest/prefer-comparison-matcher](https://lintradar.dev/rules/jest/prefer-comparison-matcher.md): Suggest using the built-in comparison matchers
- [jest/prefer-expect-resolves](https://lintradar.dev/rules/jest/prefer-expect-resolves.md): Prefer `await expect(...).resolves` over `expect(await ...)` syntax
- [jest/padding-around-test-blocks](https://lintradar.dev/rules/jest/padding-around-test-blocks.md): Enforce padding around `test` and `it` blocks
- [jest/prefer-jest-mocked](https://lintradar.dev/rules/jest/prefer-jest-mocked.md): Prefer `jest.mocked()` over `fn as jest.Mock`

---

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