Jasmine 将其嵌套在量角器/茉莉花中

Jasmine 将其嵌套在量角器/茉莉花中,jasmine,protractor,Jasmine,Protractor,我可以在量角器/Jasmine中创建嵌套的 it("outer it", function () { it("inner it", function () { expect(1).toBe(1); }); }); 我试图在循环中执行it测试用例,在每次迭代中我都想运行一个测试,例如: it("outer it", function () { for(var i=0;i<10;i++){ it("inner it", function

我可以在量角器/Jasmine中创建嵌套的

it("outer it", function () {
    it("inner it", function () {
        expect(1).toBe(1);
    });
});
我试图在循环中执行it测试用例,在每次迭代中我都想运行一个测试,例如:

it("outer it", function () {
    for(var i=0;i<10;i++){
        it("inner it", function () {
            expect(1).toBe(1);
        });
    }
});
describe ("[Components]", function() {
   var grid = new Grid();

   it("Initialize the grid for the history window", function () {
       grid.init();
   });

   for(var i=0;i<grid.length;i++){
       it("test 1", function () {
           expect(1).toBe(1);
       });
   }
it(“外部it”,函数(){

对于(var i=0;i回答您的问题,您不能将一个嵌套在另一个里面。虽然Jasmine框架不会抛出任何错误,但嵌套的里面的代码不会执行。此外,我也看不到嵌套的任何用途,因为它们是独立于compl运行的规范或函数ete是一个特定的测试步骤。它还提供了当前正在执行的函数的概述。如果您试图在循环中运行某个函数,您可以创建另一个函数,然后在for循环中调用它,类似这样-

it("outer it", function () {
    var newFunction = function(){
        expect(1).toBe(1);
    };
    for(var i=0;i<10;i++){
        newFunction();
    };
});
it(“外部it”,函数(){
var newFunction=function(){
期望(1),期望(1);
};
对于(var i=0;i
  • 如前所述-不,您不能将
    放在另一个
    块中,但是您可以将整个
    描述
    块放在另一个块中
  • 您还可以在
    循环的
    中运行
    it
    块,例如使
    it
    块有条件
  • 您可以在下面找到一个真实的代码示例(我添加for循环只是为了演示)

    描述(“E2E:环境配置测试”,功能(){
    beforeAll(函数(){
    登录();
    });
    毕竟(功能){
    注销();
    });
    描述(“成员页面配置测试”,函数(){
    
    对于(让i=0;iHi Girish,我想使用DOM初始化一个对象,初始化必须在它内部(尝试将它放在它外部,我会得到一个错误),之后我想通过我创建的对象内部的所有元素运行,对于我需要运行大量测试的每个元素,我可以使用“expect”,但我更喜欢使用“it”更多信息,当其中一个测试失败时。所以问题是所有的“it”都进入一个队列,所有不在“it”中的代码都在之前执行,所以如果我在“it”中的init值中有一个stop长度为0.Hi user1684140,请尝试初始化newFunction中的对象。它应该如上所示工作。基本上,它只是用于显示正在执行的步骤,而不是用于循环,尽管您可以在它内部循环。它始终是串行执行的,即在测试之前执行初始化1。如果您希望循环初始化后执行,然后使用量角器中可用的链接功能。
    describe("E2E: Environment configuration test", function () {
    
        beforeAll(function () {
            logIn();
        });
    
        afterAll(function () {
            logOut();
        });
    
        describe("Members page configuration test", function() {
    
        for (let i=0; i<3; i++) {
            it("Members page - columns", function () {
                //code that verifies that all columns of the page are presented
            });
        }
    
            it( "Members page - filters", function() {            
                //code that verifies that all filters of the UI are presented as expected
            });
    
            it( "Members page - eligibility feature", function() {            
                //code that verifies that if the feature is set to true then additional column must be displayed
            });
    
        });
    
        describe("Providers page configuration test", function() {
    
        // use of conditional it blocks
        // if feature is turned on run one set it blocks
        // otherwise execute another set of it blocks
            if (envConfig.providerFeature) {
    
                it( "Organizations tab configuration test", function() {            
                    //code that verifies that all elements of the current tab are displayed according to configurations of all features of the application 
                });
    
                it( "Practitioners tab configuration test", function() {});
                    //code that verifies that all elements of the current tab are displayed according to configurations of all features of the application 
            
            } else {
    
                it( "Providers page - verification of the page being disabled", function() {
                    //code that verifies that both tabs are not present in the UI
                    console.log('Providers feature is set to FALSE for the environment by default configuration, the test case will be skipped');
                });
            }
    
        });
    
        it( "Users page configuration test", function() {
             //code that verifies that all elements of the current page are displayed according to configurations of all features of the application 
        });
    
        it( "Reports page configuration test", function() {
    
            if (!envConfig.disabledReportsFeature) {
             //code that verifies that all elements of the current page are displayed according to configurations of all features of the application 
            } else {
                console.log('Reports DISABLED_REPORTS_FEATURE is set to TRUE for the environment by default configuration, the test case will be skipped');
    
            }
        });
    });