bun:test/no-identical-title
Disallow two tests or two describe blocks with the same title in one block
When two tests in the same block share a title, a failure report doesn't tell you which one failed, and filtering by name runs both. The second one is often a copy that kept the old title.
Titles are compared inside one block. The same title in two different describe blocks is fine.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"bun:test/no-identical-title" = "error" # or "warn"Examples#
example.ts1 problem
import { describe, expect, test } from "bun:test";
describe("parsePrice", () => {
test("reads a number", () => {
expect(parsePrice("12")).toBe(12);
});
test("reads a number"Test title is used multiple times in the same describe block., () => {
expect(parsePrice("12.50")).toBe(12.5);
});
});Two describe blocks next to each other are compared the same way:
example.ts1 problem
import { describe, test } from "bun:test";
describe("cart", () => {
test("adds an item", () => {});
});
describe("cart"Describe block title is used multiple times in the same describe block., () => {
test("removes an item", () => {});
});example.tsNo problems
import { describe, expect, test } from "bun:test";
describe("parsePrice", () => {
test("reads a whole number", () => {
expect(parsePrice("12")).toBe(12);
});
test("reads a decimal", () => {
expect(parsePrice("12.50")).toBe(12.5);
});
});
describe("formatPrice", () => {
test("reads a whole number", () => {
expect(formatPrice(12)).toBe("12.00");
});
});Only plain string titles are compared. A title built from a variable is skipped, and so is .each, which fills in the title for each row:
example.tsNo problems
import { expect, test } from "bun:test";
test.each([1, 2])("doubles %i", n => {
expect(double(n)).toBe(n * 2);
});
test.each([-1, -2])("doubles %i", n => {
expect(double(n)).toBe(n * 2);
});
test("rounds " + mode, () => {});
test("rounds " + mode, () => {});test.if(), test.skipIf() and the other conditional forms are skipped too, because a pair with opposite conditions is one test:
example.tsNo problems
import { expect, test } from "bun:test";
const isWindows = process.platform === "win32";
test.if(isWindows)("finds the home directory", () => {
expect(homeDirectory()).toStartWith("C:");
});
test.if(!isWindows)("finds the home directory", () => {
expect(homeDirectory()).toStartWith("/");
});