我可以在Protractor / Jasmine中创建一个嵌套它。
it("outer it", function () {
it("inner it", function () {
expect(1).toBe(1);
});
});
我正在尝试在循环中执行测试用例,并且在每次迭代中我都想运行测试,例如:
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);
});
}
});
当for循环执行时,grid.length等于0,我希望在初始化“it”之后执行for循环。
答案 0 :(得分:4)
回答你的问题,没有你不能在其他地方嵌入它。虽然Jasmine框架不会抛出任何错误,但嵌套它中的代码并不会执行。另外,我没有看到嵌套它的任何使用,因为它们是自行运行以完成特定测试步骤的规范或功能。它还概述了当前正在执行的功能。如果你试图在循环中运行某些东西,你可以创建另一个函数,然后在for循环中调用它,就像这样 -
it("outer it", function () {
var newFunction = function(){
expect(1).toBe(1);
};
for(var i=0;i<10;i++){
newFunction();
};
});
希望这会有所帮助。有关它的更多信息,请访问此处 - Jasmine Framework - it's
答案 1 :(得分:1)
it
放在另一个it
块中,但是您可以将整个describe
块放在另一个块中it
循环内运行for
块,或,例如make it
阻止条件。你可以在下面找到一个真实的代码示例(我为了演示目的添加了for循环)
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');
}
});
});
在这种情况下,控制台输出看起来很有条理
P.S。另外,我将附上一个干净的控制台图像