# assertions-in-test-cases

Rule `sonarjs/assertions-in-test-cases`. Assertions should be placed inside test cases or hooks

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1166 by reach, #467 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/assertions-in-test-cases` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-8784/) |

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/assertions-in-test-cases": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/array-callback-without-return](https://lintradar.dev/rules/sonarjs/array-callback-without-return.md): Callbacks of array methods should have return statements
- [sonarjs/assertions-in-tests](https://lintradar.dev/rules/sonarjs/assertions-in-tests.md): Tests should include assertions
- [sonarjs/arguments-order](https://lintradar.dev/rules/sonarjs/arguments-order.md): Parameters should be passed in the correct order
- [sonarjs/async-test-assertions](https://lintradar.dev/rules/sonarjs/async-test-assertions.md): Async test assertions should be awaited or returned
- [sonarjs/argument-type](https://lintradar.dev/rules/sonarjs/argument-type.md): Arguments to built-in functions should match documented types
- [sonarjs/avoid-mutating-nested-properties-of-shallow-clones](https://lintradar.dev/rules/sonarjs/avoid-mutating-nested-properties-of-shallow-clones.md): Nested properties of Lodash and Underscore.js clone results should not be mutated

---

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