eslint/rules/test-code
Test code: the SonarJS rules on tests (they apply where a test framework is used), then the relaxations test code needs (specs, testing/ helpers, benchmarks): literal tables, mutable fixtures, long describe callbacks.
39 rules, 29 on. Source: lint/eslint/rules/test-code.mjs.
| Rule | Setting | Files | What it checks | Why |
|---|---|---|---|---|
sonarjs/assertions-in-test-cases | warn | JS + TS | Assertions should be placed inside test cases or hooks | — |
sonarjs/assertions-in-tests | warn | JS + TS | Tests should include assertions | — |
sonarjs/no-duplicate-test-title | warn | JS + TS | Test titles should be unique within the same suite | — |
sonarjs/no-empty-test-title | warn | JS + TS | Test and suite titles should not be empty or whitespace-only | — |
sonarjs/no-exclusive-tests | error | JS + TS | Exclusive tests should not be committed to version control | — |
sonarjs/no-skipped-tests | warn | JS + TS | Tests should not be skipped without providing a reason | — |
sonarjs/async-test-assertions | error | JS + TS | Async test assertions should be awaited or returned | — |
sonarjs/composite-assertions | off | JS + TS | Composite assertions should be split | Off: not in the Sonar way profile of SonarQube. |
sonarjs/explicit-test-skip | warn | JS + TS | Tests should be skipped explicitly | — |
sonarjs/inverted-assertion-arguments | warn | JS + TS | Assertion arguments should be passed in the correct order | — |
sonarjs/no-code-after-done | warn | JS + TS | Tests should not execute any code after "done()" is called | — |
sonarjs/no-debug-commands-in-ui-tests | error | JS + TS | UI test debug commands should not be committed to version control | — |
sonarjs/no-duplicate-parameterized-test-case | error | JS + TS | Parameterized tests should not contain duplicate test cases | — |
sonarjs/no-empty-parameterized-test-dataset | error | JS + TS | Parameterized tests should not have empty datasets | — |
sonarjs/no-empty-test-file | warn | JS + TS | Test files should contain at least one test case | — |
sonarjs/no-fixed-wait-in-tests | warn | JS + TS | Fixed waits should not be used in tests | — |
sonarjs/no-incompatible-assertion-types | error | JS + TS | Assertions comparing incompatible types should not be made | — |
sonarjs/no-incomplete-assertions | warn | JS + TS | Assertions should be complete | — |
sonarjs/no-interpolation-in-inline-snapshots | warn | JS + TS | Inline snapshots should not contain interpolations | — |
sonarjs/no-networkidle-wait | off | JS + TS | Playwright "networkidle" waits should not be used | Off: not in the Sonar way profile of SonarQube. |
sonarjs/no-same-argument-assert | error | JS + TS | Assertions should not be given twice the same argument | — |
sonarjs/no-trivial-assertions | warn | JS + TS | Assertions should not be trivially true | — |
sonarjs/parameterized-tests | warn | JS + TS | Similar tests should be grouped in a single Parameterized test | — |
sonarjs/prefer-specific-assertions | warn | JS + TS | The most specific assertion should be used | — |
sonarjs/stable-tests | warn | JS + TS | Tests should be stable | — |
sonarjs/synchronous-exception-assertions | error | JS + TS | Synchronous exception assertions should receive synchronous callbacks | — |
sonarjs/synchronous-suite-callback | error | JS + TS | Tests should not be registered asynchronously in suite callbacks | — |
sonarjs/test-check-exception | warn | JS + TS | Tests should check which exception is thrown | — |
sonarjs/testing-library-prefer-query-by-disappearance | error | JS + TS | Testing Library disappearance waits should use non-throwing queries | — |
sonarjs/testing-library-query-assertion | error | JS + TS | Testing Library queries should match presence assertions | — |
sonarjs/vitest-mock-at-module-scope | warn | JS + TS | vi.mock should be declared at module scope | — |
@typescript-eslint/no-magic-numbers | off | test code | — | Off: test tables are made of literal numbers. |
@typescript-eslint/no-unsafe-type-assertion | off | test code | — | Off: a fake stands for a DOM element or an impossible value ({} as SVGGraphicsElement, 1 as never). |
@typescript-eslint/prefer-readonly-parameter-types | off | test code | — | Off: fixtures are plain mutable objects. |
@typescript-eslint/unbound-method | off | test code | — | Off: expect(mock.method).toHaveBeenCalled() passes a method unbound on purpose. |
max-lines-per-function | off | test code | Enforce a maximum number of lines of code in a function | Off: a describe callback holds a whole suite. |
sonarjs/max-lines-per-function | off | test code | Functions should not have too many lines of code | — |
require-unicode-regexp | off | test code | Enforce the use of u or v flag on regular expressions | Off: tests exercise patterns with every flag, or none. |
import-x/no-extraneous-dependencies | off | **/*.bench.ts | — | Custom: benchmarks import the package by its name, resolved to its build output (dist/). |