Skip to content

titleValidity

Reports describe(), it(), and test() calls with invalid titles.

✅ This rule is included in the vitest logical and logicalStrictpresets.

Reports describe(), it(), and test() calls with invalid titles.

describe(1, () => {
// ...
});
it("", () => {
// ...
});
it("it returns a number", () => {
// ...
});
it(" returns a number ", () => {
// ...
});

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, () => {
// ...
});

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", () => {
// ...
});

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, () => {
// ...
});

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", () => {
// ...
});

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", () => {
// ...
});

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.