jest/prefer-lowercase-title Style
What it does
Enforce it
, test
, describe
, and bench
to have descriptions that begin with a lowercase letter. This provides more readable test failures. This rule is not enabled by default.
Example
// invalid
it("Adds 1 + 2 to equal 3", () => {
expect(sum(1, 2)).toBe(3);
});
// valid
it("adds 1 + 2 to equal 3", () => {
expect(sum(1, 2)).toBe(3);
});
Options
{
"jest/prefer-lowercase-title": [
"error",
{
"ignore": ["describe", "test"]
}
]
}
ignore
This array option controls which Jest or Vitest functions are checked by this rule. There are four possible values:
"describe"
"test"
"it"
"bench"
By default, none of these options are enabled (the equivalent of { "ignore": [] }
).
Example of correct code for the { "ignore": ["describe"] }
option:
/* eslint jest/prefer-lowercase-title: ["error", { "ignore": ["describe"] }] */
describe("Uppercase description");
Example of correct code for the { "ignore": ["test"] }
option:
/* eslint jest/prefer-lowercase-title: ["error", { "ignore": ["test"] }] */
test("Uppercase description");
Example of correct code for the { "ignore": ["it"] }
option:
/* eslint jest/prefer-lowercase-title: ["error", { "ignore": ["it"] }] */
it("Uppercase description");
allowedPrefixes
This array option allows specifying prefixes, which contain capitals that titles can start with. This can be useful when writing tests for API endpoints, where you'd like to prefix with the HTTP method. By default, nothing is allowed (the equivalent of { "allowedPrefixes": [] }
).
Example of correct code for the { "allowedPrefixes": ["GET"] }
option:
/* eslint jest/prefer-lowercase-title: ["error", { "allowedPrefixes": ["GET"] }] */
describe("GET /live");
ignoreTopLevelDescribe
This option can be set to allow only the top-level describe
blocks to have a title starting with an upper-case letter. Example of correct code for the { "ignoreTopLevelDescribe": true }
option:
/* eslint jest/prefer-lowercase-title: ["error", { "ignoreTopLevelDescribe": true }] */
describe("MyClass", () => {
describe("#myMethod", () => {
it("does things", () => {
//
});
});
});
lowercaseFirstCharacterOnly
This option can be set to only validate that the first character of a test name is lowercased.
Example of correct code for the { "lowercaseFirstCharacterOnly": true }
option:
/* eslint vitest/prefer-lowercase-title: ["error", { "lowercaseFirstCharacterOnly": true }] */
describe("myClass", () => {
describe("myMethod", () => {
it("does things", () => {
//
});
});
});
Example of incorrect code for the { "lowercaseFirstCharacterOnly": true }
option:
/* eslint vitest/prefer-lowercase-title: ["error", { "lowercaseFirstCharacterOnly": true }] */
describe("MyClass", () => {
describe("MyMethod", () => {
it("does things", () => {
//
});
});
});
How to use
To enable this rule in the CLI or using the config file, you can use:
oxlint --deny jest/prefer-lowercase-title --jest-plugin
{
"plugins": ["jest"],
"rules": {
"jest/prefer-lowercase-title": "error"
}
}