jest/prefer-lowercase-title
Require the titles of tests and describe blocks to start with a lowercase letter
fixable
Jest 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.
--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:
bunfig.toml
[lint.rules]
"jest/prefer-lowercase-title" = "error" # or "warn"Every option, set to its default:
bunfig.toml
[lint.rules]
"jest/prefer-lowercase-title" = ["error", {
ignore = [],
allowedPrefixes = [], # list of strings
ignoreTopLevelDescribe = false,
lowercaseFirstCharacterOnly = true,
}]Examples#
example.ts1 problem
import { expect, test } from "@jest/globals";
test("Adds an item"Enforce lowercase test names, () => {
expect(cart.add(item)).toBe(1);
});example.tsNo problems
import { expect, test } from "@jest/globals";
test("adds an item", () => {
expect(cart.add(item)).toBe(1);
});Options#
| Option | Default | What it does |
|---|---|---|
ignore | [] | Functions to skip: "describe", "test", "it". "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:
example.tswith
{ "allowedPrefixes": ["GET", "POST"] }No problemsimport { test } from "@jest/globals";
test("GET /users returns a list", () => {});With ignoreTopLevelDescribe, you can name the outer describe after a class or a component. Only "Checkout" is reported here:
example.tswith
{ "ignoreTopLevelDescribe": true }1 problemimport { describe, test } from "@jest/globals";
describe("Cart", () => {
describe("Checkout"Enforce lowercase test names, () => {
test("adds an item", () => {});
});
});With { "lowercaseFirstCharacterOnly": false }:
example.tswith
{ "lowercaseFirstCharacterOnly": false }1 problemimport { test } from "@jest/globals";
test("adds an Item"Enforce lowercase test names, () => {});