Skip to content
NewBun 1.4.5 is out. Release notes
AphrodyBun

Linter · Rules

jest/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 only compared within one block. The same title in two different describe blocks is fine.

Configure

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"jest/no-identical-title" = "error" # or "warn"

Examples

Reported:

import { describe, expect, test } from "@jest/globals";

describe("parsePrice", () => {
  test("reads a number", () => {
    expect(parsePrice("12")).toBe(12);
  });

  test("reads a number", () => {
    expect(parsePrice("12.50")).toBe(12.5);
  });
});

Two describe blocks next to each other are compared the same way:

import { describe, test } from "@jest/globals";

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

describe("cart", () => {
  test("removes an item", () => {});
});

Not reported:

import { describe, expect, test } from "@jest/globals";

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:

import { expect, test } from "@jest/globals";

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, () => {});