Linter · Rules
vitest/prefer-lowercase-title
Require the titles of tests and describe blocks to start with a lowercase letter
Vitest prints a title after the titles of the blocks around it, as in cart > adds an item. A capital in the middle of that line reads like the start of a new sentence, and a mix of both styles is harder to scan.
bench titles are checked too.
--fix makes the first letter lowercase. Snapshots are stored under their test's title, so update them afterwards.
Configure
Off by default. To turn it on:
[lint.rules]
"vitest/prefer-lowercase-title" = "error" # or "warn"
Every option, set to its default:
[lint.rules]
"vitest/prefer-lowercase-title" = ["error", {
ignore = [],
allowedPrefixes = [], # list of strings
ignoreTopLevelDescribe = false,
lowercaseFirstCharacterOnly = true,
}]
Examples
Reported:
import { expect, test } from "vitest";
test("Adds an item", () => {
expect(cart.add(item)).toBe(1);
});
import { bench } from "vitest";
bench("Sorts 1000 items", () => {
items.toSorted();
});
Not reported:
import { expect, test } from "vitest";
test("adds an item", () => {
expect(cart.add(item)).toBe(1);
});
Options
| Option | Default | What it does |
|---|---|---|
ignore | [] | Functions to skip: "describe", "test", "it", "bench". "test" doesn't cover it. |
allowedPrefixes | [] | Allow a title that starts with one of these strings. |
ignoreTopLevelDescribe | false | Allow a capital in a describe that isn't inside another block. |
lowercaseFirstCharacterOnly | true | Set it to false to report an uppercase letter anywhere in the title. --fix then makes the whole title lowercase. |
allowedPrefixes is for titles that start with a name you can't change:
import { test } from "vitest";
test("GET /users returns a list", () => {});
With ignoreTopLevelDescribe, the outer describe can be named after a class or a component. Only "Checkout" is reported here:
import { describe, test } from "vitest";
describe("Cart", () => {
describe("Checkout", () => {
test("adds an item", () => {});
});
});
With { "lowercaseFirstCharacterOnly": false }:
import { test } from "vitest";
test("adds an Item", () => {});