valid-title
Configuration
Rule Details
Enforce valid titles on Jest describe, test, and it blocks. Titles should be informative strings, follow project conventions you configure, and use only allowed printf-style placeholders in array-based .each titles (see Node util.format).
This rule checks that titles are:
- not empty (including empty template literals where applicable),
- string literals (unless relaxed via options),
- not accidentally prefixed with the block keyword (for example
test('test foo')), - free of leading or trailing whitespace (unless
ignoreSpacesis enabled), - using only valid
printfspecifiers for.eachtable names, - not matching
disallowedWords(whole-word, case-insensitive) when that option is set, - satisfying
mustMatch/mustNotMatchpatterns when configured (perdescribe/test/itor a single global pattern).
Auto-fix is available for some violations (for example accidental surrounding spaces and duplicate keyword prefixes), where the implementation can rewrite the title safely.
emptyTitle
Examples of incorrect code:
Examples of correct code:
titleMustBeString
Use string literals for titles unless ignoreTypeOfDescribeName or ignoreTypeOfTestName is true.
Examples of incorrect code:
Examples of correct code:
invalidEachSpecifier
Array-based .each titles may use printf-style segments. After a single %, only p, s, d, i, f, j, o, #, and $ are accepted, and %% denotes a literal percent (aligned with eslint-plugin-jest; see the Jest and Node documentation linked above).
Examples of incorrect code:
Examples of correct code:
duplicatePrefix
Examples of incorrect code:
Examples of correct code:
accidentalSpace
Examples of incorrect code:
Examples of correct code:
Options
ignoreSpaces(defaultfalse): skip leading/trailing space checks.ignoreTypeOfDescribeName/ignoreTypeOfTestName(defaultfalse): allow non-string first arguments fordescribeortest/itrespectively.disallowedWords: list of words that must not appear as whole words in titles (case-insensitive).mustMatch/mustNotMatch: ECMAScript regular expressions as strings, either one pattern for all block kinds or an object keyed bydescribe,test, andit. You can pass a two-element array[pattern, customMessage]to surface*Custommessage variants.
For full option examples and edge cases, see the upstream rule documentation below.