admin管理员组

文章数量:1323714

 describe('some test', function() {
  for(i = 0; i < someData.length; i++) {
   it("test scenario "+i, function() {
   assert.deepEqual(someValue, someData[i]);
   });
  }
 });

Having the above code is not printing mutiple pass results. It is printing the below (in green color) in the console.

0 passing (42ms)
 describe('some test', function() {
  for(i = 0; i < someData.length; i++) {
   it("test scenario "+i, function() {
   assert.deepEqual(someValue, someData[i]);
   });
  }
 });

Having the above code is not printing mutiple pass results. It is printing the below (in green color) in the console.

0 passing (42ms)
Share Improve this question asked Oct 14, 2019 at 19:49 krishkrish 1962 silver badges5 bronze badges 1
  • Possibly related: stackoverflow./questions/750486/… – Taplar Commented Oct 14, 2019 at 19:55
Add a ment  | 

1 Answer 1

Reset to default 6

All the details are here: https://github./mochajs/mocha/issues/3074

Mocha doesn't support such behavior. The two most famous workarounds are:

  • IIFE
  • forEach

I would the forEach to be slightly more elegant, here is the possible solution by Scott Santucci (github), and modified by me for your case:

someData.forEach(function(value, i) {
  it(`test scenario ${i}`, function() {
    assert.deepEqual(testValue, value);
  })
})

本文标签: javascriptHow can I use quotitquot in a for loop in mocha testingStack Overflow