Jest
Jest test source rules from eslint-plugin-jest. Apply to TypeScript test files that use the Jest runner (describe, test/it, expect, lifecycle hooks). They guard test-quality patterns the type system cannot detect, unended assertions, focused tests left behind, duplicate hook calls.
Source: eslint-plugin-jest (MIT).
jest/expect-expect: Require every Jest test body to contain at least oneexpect(...)call.jest/max-expects: Limit the number ofexpect(...)calls inside a single Jest test body.jest/no-conditional-expect: Rejectexpect(...)calls underif/try/catchor other conditional branches in Jest tests.jest/no-conditional-in-test: Reject conditional logic (if/switch/ternary) inside Jest test bodies.jest/no-disabled-tests: Rejecttest.skip,xit,xdescribe, and other disabled Jest tests.jest/no-done-callback: Rejectdonecallback parameters in Jest tests and hooks.jest/no-duplicate-hooks: Reject duplicate setup/teardown hook calls (beforeEach/beforeAll/etc.) within the samedescribeblock.jest/no-export: Rejectexportdeclarations in Jest test files.jest/no-focused-tests: Rejecttest.only,fit,fdescribe, and other focused Jest tests.jest/no-hooks: Reject Jest setup/teardown hooks altogether.jest/no-identical-title: Reject duplicate test ordescribetitles at the same suite level. The runner cannot distinguish two tests with the same name in error output.jest/no-standalone-expect: Rejectexpect(...)calls outside the body of a Jest test or lifecycle hook.jest/no-test-prefixes: Rejectxit,fit,xdescribe,fdescribe, and the rest of the single-letter Jest test prefix aliases.jest/no-test-return-statement: Reject non-Promisereturnstatements from Jest test bodies.jest/prefer-to-have-length: Preferexpect(value).toHaveLength(n)over asserting onvalue.lengthdirectly withtoBe.jest/require-to-throw-message: Require a message argument onexpect(...).toThrow(...)so a regression with a different error type still surfaces clearly.jest/valid-describe-callback: Validate the shape of Jestdescribecallbacks.jest/valid-expect: Validateexpect(...)arity and matcher chaining: exactly one argument, terminated by a matcher call, and async matchers properly awaited.jest/valid-title: Require non-empty static Jest test anddescribetitles.
Last updated on