Node.js Mocha selenium web中的嵌套forEach测试失败
我正在编写一个测试脚本,它应该执行以下操作(这是一个示例,但逻辑和结构是相同的)Node.js Mocha selenium web中的嵌套forEach测试失败,node.js,asynchronous,mocha.js,describe,Node.js,Asynchronous,Mocha.js,Describe,我正在编写一个测试脚本,它应该执行以下操作(这是一个示例,但逻辑和结构是相同的) 对于arr1中的每个项,调用函数arr_func_1 在arr_func_1中,记录当前项,然后为arr2中的每个项调用函数arr_func_2 在arr_func_2内,记录当前项 调用被包装在its()中,因为如果数组中的一个元素失败,那么它需要正常地失败并继续到数组中的下一个元素 这方面的预期结果应该是: 一, 10 20 30 2. 10 20 30 3. 10 20 三十 相反,我收到了 1. 2.
- 对于arr1中的每个项,调用函数arr_func_1
- 在arr_func_1中,记录当前项,然后为arr2中的每个项调用函数arr_func_2
- 在arr_func_2内,记录当前项
var arr1 = [1,2,3]
var arr2 = [10,20,30]
function arr_func_1(item){
console.log(item);
arr2.forEach(function(item){
it('should loop through arr2, function(){
arr_func_2(item);
})
});
}
function arr_func_2(item){
console.log(item);
}
describe('test case', function(){
arr1.forEach(function(item){
it('should loop through array 1', function(){
arr_func_1(item);
})
}
})
测试应该在运行之前定义<代码>应循环通过arr2测试是在
应循环通过数组1
运行时定义的,因此在测试运行期间忽略它们
除循环外,这类似于:
describe('test case', function(){
it('should loop through array 1', function(){
it('should loop through arr2, function(){})
})
})
it
块不应在另一个it
中定义
它可能需要:
describe('test case', function(){
for (const item1 of arr1) {
it('should loop through array 1', function(){...});
for (const item2 of arr2) {
it('should loop through array 2', function(){...});
}
}
});
我懂了。我将如何着手实现所需要的?你到底需要什么?代码没有解释这些数组的用途。我们的系统中有modals。每个模态包含选项卡,每个选项卡可以包含子选项卡。所以我想做的是,对于每个标签,测试其中的子标签,而不是在我的工作计算机上。我会尽快试一试,然后再给你回复。谢谢你的意见!