valid-title
Added in v0.8.0Configuration
Rule Details
Enforce valid titles on Rstest describe, test, and it blocks. Titles should be informative strings, follow project conventions you configure, and use only the printf-style placeholders that Rstest actually expands in array-based .each / .for titles.
This rule checks that titles are:
- not empty (including empty template literals),
- 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 array-based.each/.fortable 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 accidental surrounding spaces and duplicate keyword prefixes.
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
Titles of array-based .each and .for registrations are formatted at runtime. After a single %, only s, d, j, i, f, o, O, c, #, and $ are accepted, and %% denotes a literal percent.
Examples of incorrect code:
Examples of correct code:
Tagged-template tables are not checked, because they interpolate with $name rather than printf specifiers and a bare % in them is literal text:
duplicatePrefix
Examples of incorrect code:
Examples of correct code:
accidentalSpace
Examples of incorrect code:
Examples of correct code:
Differences from jest/valid-title
The rule is otherwise a port of jest/valid-title, with three differences that follow from how Rstest itself behaves.
The set of valid printf specifiers is Rstest's, not Jest's. Rstest formats parameterized titles with Node's util.format semantics, accepting s, d, j, i, f, o, O, c, and % after a %, while Jest uses its own pretty-format placeholder set. So:
.for titles are checked too. Rstest has both .each and .for, and both format their titles the same way. Jest has no .for.
There are no f / x prefixed aliases. Rstest provides no fit, xit, xtest, fdescribe, or xdescribe, so the keyword compared against the title is always the API being registered — test, it, or describe — even when it was imported or aliased under another name. import { it as xit } from '@rstest/core'; xit('it works', fn) is reported, and mustMatch: { test: … } applies to import { test as check } …; check(…).
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.