我是摩卡新手。我在循环中调用it
声明。我有一个工作脚本,我在此添加以询问是否有更好的方法来执行此操作。在循环中调用语句
以下是工作脚本
var xl = require('./excel');
describe("Register User", function(){
var csv = xl.readExcel(); //gets multiple rows as csv.
var arrRows = csv.split("\n");
var arrRow = []; //will store the current row under test
var iRow = 0;
before(function() {
//can variables csv and arrRows be initialized here?
});
beforeEach(function(){
arrRow = xl.splitCsvToArray(arrRows[iRow++]);
});
for(var i = 0; i < arrRows.length - 1; i++){
it('test case X', function(){
console.log("current row is: " + iRow);
console.log("1st column is: " + arrRow[0][1]);
console.log("2nd column is: " + arrRow[0][2]);
});
}
});
结果是提前
1st column is: col2row3
2nd column is: col3row3
√ test case X
current row is: 5
1st column is: col2row4
2nd column is: col3row4
√ test case X
current row is: 6
1st column is: col2row5
2nd column is: col3row5
√ test case X
current row is: 7
1st column is: col2row6
2nd column is: col3row6
√ test case X
7 passing (27ms)
感谢。
Thanks @Louis。我已经按照建议通过添加初始化来尝试,就像您在'之前'显示的那样。然而,在这行''for(var i = 0; i
我已经编辑了您的问题中的代码,以反映您在此评论中所说的内容,并且编辑了我的答案以处理问题。 – Louis
感谢您对患者详细的说明。它非常有帮助。 –