jest/max-nested-describe

Enforce a maximum depth of nested describe() calls

Every level of describe can add its own hooks and variables. To understand a test that's many levels deep, you have to read all the blocks around it, and the test's full name gets long.

By default describe blocks can be 5 levels deep. A describe at a deeper level is reported.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"jest/max-nested-describe" = "error" # or "warn"

Every option, set to its default:

bunfig.toml
[lint.rules]
"jest/max-nested-describe" = ["error", {
  max = 5,
}]

Examples#

These examples use a maximum of 2:

bunfig.toml
[lint.rules]
"jest/max-nested-describe" = ["error", { max = 2 }]
example.tswith { "max": 2 }1 problem
import { describe, expect, test } from "@jest/globals";

describe("cart", () => {
  describe("checkout", () => {
    describe("with a coupon", () => {
      test("lowers the total", () => {
        expect(checkout({ coupon: "SAVE10" }).total).toBe(90);
      });
    });
  });
});
example.tswith { "max": 2 }No problems
import { describe, expect, test } from "@jest/globals";

describe("cart", () => {
  describe("checkout", () => {
    test("a coupon lowers the total", () => {
      expect(checkout({ coupon: "SAVE10" }).total).toBe(90);
    });
  });
});

Options#

OptionDefaultWhat it does
max5The number of levels allowed.