简体   繁体   English

为什么不建议将测试放在describe块中?

[英]Why is it not recommended to put tests in a describe block?

According to React documentation : 根据React文档

You may optionally wrap them in describe() blocks for logical grouping but this is neither required nor recommended. 您可以选择将它们包装在describe()块中以进行逻辑分组,但这不是必需的,也不建议这样做。

I wonder why putting it blocks in describe blocks is not recommended? 我想知道为什么不建议将其放在描述块中吗?

I would like to know the author opinion on the subject, but I believe it is because describe() allows you to group tests within the same file, and to nest them. 我想知道作者对此主题的看法,但是我相信这是因为describe()允许您将测试分组在同一文件中,并将其嵌套。

Nesting is dangerous, because it's easy to take it too far. 嵌套很危险,因为很容易将其移到太远。 When you have three or more levels of nesting, and each level runs setup code in its own lifecycle methods (beforeAll, beforeEach, afterAll, afterEach), you have to look at many places throughout the file just to understand what's going on in one test. 当您具有三个或三个以上的嵌套级别,并且每个级别都在其自己的生命周期方法(beforeAll,beforeEach,afterAll,afterEach)中运行设置代码时,您必须查看整个文件的许多位置,才能了解一次测试中的情况。

I believe breaking down the tests group in different files is better than abusing describe(). 我认为将测试组分解为不同的文件比滥用describe()更好。

As a wise man once said: "with great power comes great responsibility" 正如一个聪明人曾经说过的:“能力越大,责任就越大”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM