bun:test/prefer-lowercase-title

Require the titles of tests and describe blocks to start with a lowercase letter

fixable

bun test 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. It doesn't touch titles in a file that uses toMatchSnapshot() or toThrowErrorMatchingSnapshot(), because snapshots are stored under their test's title.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"bun:test/prefer-lowercase-title" = "error" # or "warn"

Every option, set to its default:

bunfig.toml
[lint.rules]
"bun:test/prefer-lowercase-title" = ["error", {
  ignore = [], # list of "describe", "it" or "test"
  allowedPrefixes = [], # list of strings
  ignoreTopLevelDescribe = false,
  lowercaseFirstCharacterOnly = true,
}]

Examples#

example.ts1 problem
import { expect, test } from "bun:test";

test("Adds an item", () => {
  expect(cart.add(item)).toBe(1);
});
example.tsNo problems
import { expect, test } from "bun:test";

test("adds an item", () => {
  expect(cart.add(item)).toBe(1);
});

Options#

OptionDefaultWhat 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.
ignoreTopLevelDescribefalseAllow a capital in a describe that isn't inside another block.
lowercaseFirstCharacterOnlytrueSet 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 problems
import { test } from "bun:test";

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:

example.tswith { "ignoreTopLevelDescribe": true }1 problem
import { describe, test } from "bun:test";

describe("Cart", () => {
  describe("Checkout", () => {
    test("adds an item", () => {});
  });
});

With { "lowercaseFirstCharacterOnly": false }:

example.tswith { "lowercaseFirstCharacterOnly": false }1 problem
import { test } from "bun:test";

test("adds an Item", () => {});