titleValidity
Reports
describe(),it(), andtest()calls with invalid titles.
✅ This rule is included in the vitestlogicalandlogicalStrictpresets.
Reports describe(), it(), and test() calls with invalid titles.
Examples
Section titled “Examples”describe(1, () => { // ...});it("", () => { // ...});it("it returns a number", () => { // ...});it(" returns a number ", () => { // ...});describe("1", () => { // ...});it("returns a number", () => { // ...});declare function getValue(): number;
describe(getValue, () => { // ...});Options
Section titled “Options”allowArguments
Section titled “allowArguments”Whether to allow identifiers as titles.
Defaults to false.
Only identifiers are skipped by this option.
Function calls such as getTitle() and property accesses such as config.title are not skipped, and are still reported.
Examples of incorrect code for this rule with the { "allowArguments": true } option:
declare function getTitle(): unknown;
it(getTitle(), () => { // ...});declare const config: { title: unknown };
it(config.title, () => { // ...});Examples of correct code for this rule with the { "allowArguments": true } option:
declare const title: unknown;
it(title, () => { // ...});disallowedWords
Section titled “disallowedWords”Words that are not allowed to appear in titles.
Defaults to [].
Words are matched case-insensitively on word boundaries, against the title string only.
Because of the word boundaries, "skip" does not match a title containing skipped.
Examples of incorrect code for this rule with the { "disallowedWords": ["skips"] } option:
it("skips the empty case", () => { // ...});Examples of correct code for this rule with the { "disallowedWords": ["skips"] } option:
it("ignores the empty case", () => { // ...});ignoreTypeOfDescribeName
Section titled “ignoreTypeOfDescribeName”Whether to skip checking the type of describe() titles.
Defaults to false.
Examples of correct code for this rule with the { "ignoreTypeOfDescribeName": true } option:
declare const value: unknown;
describe(typeof value, () => { // ...});mustMatch
Section titled “mustMatch”Regular expressions that titles must match, optionally with a custom message. Not set by default.
A string or a [pattern, message] pair applies to describe, it, and test alike.
An object applies a separate pattern per function:
{ "mustMatch": { "it": ["^should ", "Start test titles with \"should\"."] }}Aliases map onto those three keys: xdescribe uses describe, fit and xit use it, and xtest uses test.
Examples of incorrect code for this rule with the { "mustMatch": "^should " } option:
it("returns a number", () => { // ...});Examples of correct code for this rule with the { "mustMatch": "^should " } option:
it("should return a number", () => { // ...});mustNotMatch
Section titled “mustNotMatch”Regular expressions that titles must not match, optionally with a custom message. Not set by default.
It takes the same shapes as mustMatch.
When a title matches mustNotMatch, that is reported and mustMatch is not checked.
Examples of incorrect code for this rule with the { "mustNotMatch": "^should " } option:
it("should return a number", () => { // ...});Examples of correct code for this rule with the { "mustNotMatch": "^should " } option:
it("returns a number", () => { // ...});When Not To Use It
Section titled “When Not To Use It”Projects that lean on generated titles, or that have a large existing suite whose titles would be disruptive to rename, might prefer to enable only the options they need rather than the whole rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
vitest/valid-title - Oxlint:
vitest/valid-title
