jest/max-nested-describe Style ​
What it does ​
This rule enforces a maximum depth to nested describe()
calls.
Why is this bad? ​
Nesting describe()
blocks too deeply can make the test suite hard to read and understand.
Example ​
The following patterns are considered warnings (with the default option of { "max": 5 }
):
/// /// Examples of incorrect code for this rule:
javascript
describe("foo", () => {
describe("bar", () => {
describe("baz", () => {
describe("qux", () => {
describe("quxx", () => {
describe("too many", () => {
it("should get something", () => {
expect(getSomething()).toBe("Something");
});
});
});
});
});
});
});
describe("foo", function () {
describe("bar", function () {
describe("baz", function () {
describe("qux", function () {
describe("quxx", function () {
describe("too many", function () {
it("should get something", () => {
expect(getSomething()).toBe("Something");
});
});
});
});
});
});
});
Examples of correct code for this rule:
ts
describe("foo", () => {
describe("bar", () => {
it("should get something", () => {
expect(getSomething()).toBe("Something");
});
});
describe("qux", () => {
it("should get something", () => {
expect(getSomething()).toBe("Something");
});
});
});
describe("foo2", function () {
it("should get something", () => {
expect(getSomething()).toBe("Something");
});
});
describe("foo", function () {
describe("bar", function () {
describe("baz", function () {
describe("qux", function () {
describe("this is the limit", function () {
it("should get something", () => {
expect(getSomething()).toBe("Something");
});
});
});
});
});
});
How to use ​
To enable this rule in the CLI or using the config file, you can use:
bash
oxlint --deny jest/max-nested-describe --jest-plugin
json
{
"plugins": ["jest"],
"rules": {
"jest/max-nested-describe": "error"
}
}