Skip to content

useValidTestTitle (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"useValidTestTitle": "error"
}
}
}
}

Enforce valid titles for unit test cases and test suites.

Checks that the titles of test blocks (describe, test, it) are valid:

  • Titles must not be empty.
  • Titles must not have accidental leading or trailing whitespace.
  • Titles must be string or template literals.
  • Titles must not contain disallowed words (if configured).
it("", () => {});
code-block.js:1:4 lint/nursery/useValidTestTitle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The test title is empty.

> 1 │ it("", () => {});
^^
2 │

A title is required to identify the test in test reports.

Provide a descriptive title for this test.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

describe(" foo", () => {});
code-block.js:1:10 lint/nursery/useValidTestTitle  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The describe title has leading or trailing whitespace.

> 1 │ describe(" foo", () => {});
^^^^^^
2 │

Accidental whitespace can cause inconsistent test output and formatting issues in reports.

Remove the accidental whitespace at the start of the title.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Safe fix: Trim leading and trailing whitespace from the title.

1 │ describe("·foo",·()·=>·{});
-
test(123, () => {});
code-block.js:1:6 lint/nursery/useValidTestTitle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The test title is not a string.

> 1 │ test(123, () => {});
^^^
2 │

Test titles must be strings to ensure test runners and reporters can properly display them.

Provide a string literal or template literal as the title.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

it("should work", () => {});
describe("my suite", () => {});

A list of words that are not allowed in test titles. Matching is whole-word and case-insensitive.

Default: []

biome.json
{
"linter": {
"rules": {
"nursery": {
"useValidTestTitle": {
"level": "on",
"options": {
"disallowedWords": [
"skip",
"only"
]
}
}
}
}
}
}