Skip to content

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.

RuleSettingFilesWhat it checksWhy
sonarjs/assertions-in-test-caseswarnJS + TSAssertions should be placed inside test cases or hooks—
sonarjs/assertions-in-testswarnJS + TSTests should include assertions—
sonarjs/no-duplicate-test-titlewarnJS + TSTest titles should be unique within the same suite—
sonarjs/no-empty-test-titlewarnJS + TSTest and suite titles should not be empty or whitespace-only—
sonarjs/no-exclusive-testserrorJS + TSExclusive tests should not be committed to version control—
sonarjs/no-skipped-testswarnJS + TSTests should not be skipped without providing a reason—
sonarjs/async-test-assertionserrorJS + TSAsync test assertions should be awaited or returned—
sonarjs/composite-assertionsoffJS + TSComposite assertions should be splitOff: not in the Sonar way profile of SonarQube.
sonarjs/explicit-test-skipwarnJS + TSTests should be skipped explicitly—
sonarjs/inverted-assertion-argumentswarnJS + TSAssertion arguments should be passed in the correct order—
sonarjs/no-code-after-donewarnJS + TSTests should not execute any code after "done()" is called—
sonarjs/no-debug-commands-in-ui-testserrorJS + TSUI test debug commands should not be committed to version control—
sonarjs/no-duplicate-parameterized-test-caseerrorJS + TSParameterized tests should not contain duplicate test cases—
sonarjs/no-empty-parameterized-test-dataseterrorJS + TSParameterized tests should not have empty datasets—
sonarjs/no-empty-test-filewarnJS + TSTest files should contain at least one test case—
sonarjs/no-fixed-wait-in-testswarnJS + TSFixed waits should not be used in tests—
sonarjs/no-incompatible-assertion-typeserrorJS + TSAssertions comparing incompatible types should not be made—
sonarjs/no-incomplete-assertionswarnJS + TSAssertions should be complete—
sonarjs/no-interpolation-in-inline-snapshotswarnJS + TSInline snapshots should not contain interpolations—
sonarjs/no-networkidle-waitoffJS + TSPlaywright "networkidle" waits should not be usedOff: not in the Sonar way profile of SonarQube.
sonarjs/no-same-argument-asserterrorJS + TSAssertions should not be given twice the same argument—
sonarjs/no-trivial-assertionswarnJS + TSAssertions should not be trivially true—
sonarjs/parameterized-testswarnJS + TSSimilar tests should be grouped in a single Parameterized test—
sonarjs/prefer-specific-assertionswarnJS + TSThe most specific assertion should be used—
sonarjs/stable-testswarnJS + TSTests should be stable—
sonarjs/synchronous-exception-assertionserrorJS + TSSynchronous exception assertions should receive synchronous callbacks—
sonarjs/synchronous-suite-callbackerrorJS + TSTests should not be registered asynchronously in suite callbacks—
sonarjs/test-check-exceptionwarnJS + TSTests should check which exception is thrown—
sonarjs/testing-library-prefer-query-by-disappearanceerrorJS + TSTesting Library disappearance waits should use non-throwing queries—
sonarjs/testing-library-query-assertionerrorJS + TSTesting Library queries should match presence assertions—
sonarjs/vitest-mock-at-module-scopewarnJS + TSvi.mock should be declared at module scope—
@typescript-eslint/no-magic-numbersofftest code—Off: test tables are made of literal numbers.
@typescript-eslint/no-unsafe-type-assertionofftest code—Off: a fake stands for a DOM element or an impossible value ({} as SVGGraphicsElement, 1 as never).
@typescript-eslint/prefer-readonly-parameter-typesofftest code—Off: fixtures are plain mutable objects.
@typescript-eslint/unbound-methodofftest code—Off: expect(mock.method).toHaveBeenCalled() passes a method unbound on purpose.
max-lines-per-functionofftest codeEnforce a maximum number of lines of code in a functionOff: a describe callback holds a whole suite.
sonarjs/max-lines-per-functionofftest codeFunctions should not have too many lines of code—
require-unicode-regexpofftest codeEnforce the use of u or v flag on regular expressionsOff: tests exercise patterns with every flag, or none.
import-x/no-extraneous-dependenciesoff**/*.bench.ts—Custom: benchmarks import the package by its name, resolved to its build output (dist/).

Generated from the JSDoc of the sources.