I am new to Mocha. i am calling the it
statement in a loop. I have a working script which i add here to ask if there is a better way to do this.
The following is the working script
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]);
});
}
});
result is
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 in advance.