3

I am writing protractor test suites, and need to test something that is uses pages generated from another suite. I can only figure out one way to write the test, but it doesn't seem like a good way to write it:

var someStuffToSave = [];

describe('description of first thing', function(){
    it('should generate some things', function(){
        someStuffToSave.push(generateSomeThings());
    });
    it('should generate some things', function(){
        someStuffToSave.push(generateSomeThings());
    });
    it('should generate some things', function(){
        someStuffToSave.push(generateSomeThings());
        element(by.id("something")).getText().then(function(){
          for(var i = 0; i < someStuffToSave.length; i++) (function(){
             var idx = i;
             describe('thing analysis' + idx, function(){
                it('should be something', function(){
                   expect(someStuffToSave[idx]).toEqual(true);
                });
             });
          })();
      });
    }); 
});

I would much rather do something like this, but the problem is the internals of the second describe execute right away, and do not wait for the first describe to finish.

var someStuffToSave = [];
describe('description of some thing', function(){
    it('should generate some things', function(){
        someStuffToSave.push(generateSomeThings());
    });
    it('should generate some things', function(){
        someStuffToSave.push(generateSomeThings());
    });
    it('should generate some things', function(){
        someStuffToSave.push(generateSomeThings);
    }); 
});
describe('analyzing things', function(){
    for(var i = 0; i < someStuffToSave.length; i++)function(){
        var idx = i;
        describe('thing ' + idx, function(){
            it('should be something', function(){
                expect(someStuffToSave[idx]).toEqual(true);
            });
        });
     }
});

is there some way to write this without the 'then' inside the it in the first describe?

4

1 回答 1

1

一般来说,你不应该在 Jasmine 中的“描述”块内进行任何设置登录。那里的代码在 Jasmine 设置测试时运行,但顺序不正确。如果您只是将 for 循环放在“it”块中,您的第二种方法应该可以工作。

于 2014-07-22T18:56:21.873 回答