bun:test/valid-describe-callback

Require describe to get a callback that is a function with no parameters

error by default

bun test runs the describe callback to collect the tests inside it. Without a callback there's nothing to collect. The callback isn't a test, so it has no done to call.

This rule is on by default in files that import from "bun:test".

Configure#

On by default as an error. To turn it off:

bunfig.toml
[lint.rules]
"bun:test/valid-describe-callback" = "off" # or "warn"

Examples#

example.ts3 problems
import { describe, test } from "bun:test";

describe("cart"); // no callback

describe("cart", "adds an item"); // not a function

describe("cart", (done) => {
  test("adds an item", () => {});
  done();
});
example.tsNo problems
import { describe, expect, test } from "bun:test";

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

An async callback is allowed, because bun test waits for the promise it returns:

example.tsNo problems
import { describe, expect, test } from "bun:test";

describe("checkout", async () => {
  const rates = await loadRates();

  test("adds the tax", () => {
    expect(total(100, rates)).toBe(108);
  });
});

describe.todo and describe.skip only need a title. A callback passed by name is assumed to be a function:

example.tsNo problems
import { describe } from "bun:test";
import { cartTests } from "./shared";

describe.todo("refunds");
describe.skip("exports");

describe("cart", cartTests);

The describe.each callback gets a row's values, so it can have parameters:

example.tsNo problems
import { describe, expect, test } from "bun:test";

describe.each([1, 2, 3])("cart with %i items", (count) => {
  test("counts them", () => {
    expect(fill(count).length).toBe(count);
  });
});