[英]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: 我不确定你想通过在同一个描述中使用多个文件来完成什么,但我能想到的一些事情是:
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=
的全名开头检查该术语。
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. 如果所有规范都需要共享的
beforeEach
或afterEach
,那么您可以做的是在共享文件中定义一个方法(例如specHelper.js),然后从每个文件中的beforeEach
或afterEach
调用该方法。
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.