---
url: /docs/guide/usage/linter/rules/jest/max-nested-describe.md
---

### 它的作用

此规则强制限制嵌套 `describe()` 调用的最大深度。

### 为什么这不好？

`describe()` 块嵌套得太深会让测试套件难以阅读和理解。

### 示例

以下模式被视为警告（默认选项为
`{ "max": 5 } `）：

此规则的**错误**代码示例：

```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");
            });
          });
        });
      });
    });
  });
});
```

此规则的**正确**代码示例：

```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");
          });
        });
      });
    });
  });
});
```

## 配置

此规则接受一个包含以下属性的配置对象：

### max

type: `integer`

default: `5`

允许的 `describe` 调用最大嵌套深度。

## 如何使用

## 版本

此规则添加于 v0.4.4。

## 参考资料
