# assertions-in-tests

Rule `sonarjs/assertions-in-tests`. Tests should include assertions

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

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
const expect = require('chai').expect;

describe("No assertion", function() {
    it("doesn't test anything", function() { // Noncompliant
        const str = "";
    });
});
```

### Correct: the rule accepts this

```js
const expect = require('chai').expect;

describe("Has assertions", function() {
    it("tests a string", function() {
        const str = "";
        expect(str).to.be.a('string');
    });
});
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/assertions-in-tests": "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/assertions-in-test-cases](https://lintradar.dev/rules/sonarjs/assertions-in-test-cases.md): Assertions should be placed inside test cases or hooks
- [sonarjs/async-test-assertions](https://lintradar.dev/rules/sonarjs/async-test-assertions.md): Async test assertions should be awaited or returned
- [sonarjs/array-callback-without-return](https://lintradar.dev/rules/sonarjs/array-callback-without-return.md): Callbacks of array methods should have return statements
- [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
- [sonarjs/arguments-order](https://lintradar.dev/rules/sonarjs/arguments-order.md): Parameters should be passed in the correct order
- [sonarjs/aws-apigateway-public-api](https://lintradar.dev/rules/sonarjs/aws-apigateway-public-api.md): AWS API Gateway should require authentication

---

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