简体   繁体   English

在Jasmine中为多个相关文件使用describe块

[英]Using a describe block for multiple related files in Jasmine

如果我有一组相关的测试,我不想在一个文件中,但我仍然希望将它们全部包含在describe块中,我该怎么办呢?

Jasmine doesn't supply a way to do this out of the box, because you pass in a function as the second argument to describe , there isn't a way to combine any given functions, even if jasmine was trying to detect that some subset of your describe s had the same description. Jasmine没有提供开箱即用的方法,因为你传递一个函数作为describe的第二个参数,没有办法组合任何给定的函数,即使茉莉花试图检测到某些子集你的describe有相同的描述。 I'm not sure what you're trying to accomplish by having multiple files in the same describe, but a few things I can think of are: 我不确定你想通过在同一个描述中使用多个文件来完成什么,但我能想到的一些事情是:

  1. If your goal is to have the specs fall under the same filter in the html reporter, this should happen automatically if the describes are all named the same. 如果您的目标是让规范属于html报告器中的相同过滤器,则如果描述的名称相同,则应自动执行此操作。 When the html reporter checks whether a spec should be run based on the spec= query param, the term is checked against the beginning of full name of the spec. 当html报告者检查是否应该根据spec= query参数运行规范时,将根据spec=的全名开头检查该术语。

  2. If all of the specs need to have a shared beforeEach or afterEach , what you can do is define a method in a shared file (eg specHelper.js), and then call that method from a beforeEach or afterEach from within each file. 如果所有规范都需要共享的beforeEachafterEach ,那么您可以做的是在共享文件中定义一个方法(例如specHelper.js),然后从每个文件中的beforeEachafterEach调用该方法。

If you want both, there should be no problems with combining both approaches above. 如果你想要两者,那么结合上述两种方法应该没有问题。

You can have few describe with same spec suite title (first describe string parameter). 你可以用很少的describe使用相同的规范套件标题(首先描述字符串参数)。 Then even if specs are in separate files - they will appear in same describe block. 然后即使规格在单独的文件中 - 它们也会出现在同一个describe块中。 It does work for me in 2.3.4. 它在2.3.4中对我有用。

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

相关问题 茉莉花-如何设置describe块的超时时间? - Jasmine - How to set a timeout for a describe block? 量角器Jasmine描述嵌套在它块内的块 - Protractor Jasmine describe blocks nested within an it block 如何不为茉莉花中的特定Describe()块在BeforeAll中运行某些代码 - How not to run certain codes in BeforeAll for a specific Describe() block in Jasmine 如何抽象和重用茉莉花中的describe()块? - how to abstract and re-use a describe() block in jasmine? 有没有办法计算jasmine describe块中的测试数量? - Is there a way to get the count for the number of tests in a jasmine describe block? 运行jasmine测试时,我怎么知道我是否在一个描述块中,在每个块之前还是阻塞? - When running jasmine tests, how can I know if I am in a describe block, beforeEach block or it block? 在多个JS文件中使用Jasmine,避免db竞态 - Using Jasmine in multiple JS files, avoiding db race conditions 相关的js文件和html块的css文件 - Related js files and css files of html block Jest - 在 describe 块中导入多个测试,重用 beforeEach() 中定义的变量 - Jest - import multiple tests in a describe block, reusing variables defined in beforeEach() DRYing jasmine嵌套描述块 - DRYing jasmine nested describe blocks
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM