---
url: /docs/guide/usage/linter/rules/vitest/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 中加入。

## 参考资料
