简体   繁体   English

如何不为茉莉花中的特定Describe()块在BeforeAll中运行某些代码

[英]How not to run certain codes in BeforeAll for a specific Describe() block in Jasmine

I'm working on a Jasmine unit test spec. 我正在研究Jasmine单元测试规范。 There are multiple describe() blocks in the JS file. JS文件中有多个describe()块。

In BeforeAll , I want to only call function for Describe-Block "A" and "C", so how can I do that? BeforeAll ,我只想为Describe-Block“ A”和“ C”调用函数,那么该怎么做? The logic is like this: 逻辑是这样的:

//SampleSpec.js
BeforeAll(function() {
        if(descirbe name !== "B"){
            DoSomething();
        }
});

descirbe("A", function() {
        //...
});

descirbe("B", function() {
        //..
});

descirbe("C", function() {
        //...
});

Without knowing more about your setup, beforeAll will always run. 在不了解您的设置的情况下, beforeAll将始终运行。 But you could create your own sharedSetup() function & just call it at the top of A and C , but not B . 但是您可以创建自己的sharedSetup()函数并仅在AC的顶部调用它,但不能在B的顶部调用它。 If it is promise based, you can sharedSetup.then() to defer running the rest of your code until the promise resolves. 如果基于承诺,则可以sharedSetup.then()推迟运行其余代码,直到承诺解决为止。

This is beneficial as it keeps the logic for a test clearly within that test, rather than having a conditional for the test elsewhere in the test file. 这是有益的,因为它使测试的逻辑清晰地保持在该测试中,而不是在测试文件中的其他位置具有测试的条件。

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

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