Skip to content

duplicate-test-name ​

Two tests with the same name in one describe (or in a file's top level), or two describes of the same name next to each other. Reported in test files. A warning by default.

Why: a report that says "adds" failed points at either test; -t "adds" / --test-name-pattern runs both; snapshot keys get numbered by order, so reordering the tests swaps their snapshots. It usually means a test was copied and only its body changed, so its name no longer says what it checks. Guide: Testing.

ts
import assert from "node:assert/strict";
import { describe, test } from "node:test";

function total(prices: readonly number[]): number {
  return prices.reduce((sum, price) => sum + price, 0);
}

describe("total", () => {
  test("adds", () => {
    assert.equal(total([3, 4]), 7);
  });
  test("adds", () => {
    assert.equal(total([]), 0);
  });
});
✓ Accepted0 diagnostics
ts
import assert from "node:assert/strict";
import { describe, test } from "node:test";

function total(prices: readonly number[]): number {
  return prices.reduce((sum, price) => sum + price, 0);
}

describe("total", () => {
  test("adds the prices", () => {
    assert.equal(total([3, 4]), 7);
  });
  test("is 0 for no prices", () => {
    assert.equal(total([]), 0);
  });
});

What the rule can't see ​

Names computed at run time: a template with substitutions, a variable, and the rows of test.each / describe.each (their names are filled in per row).

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra