Ezeewei Ezeewei - 2 months ago 7
Javascript Question

loop through it() in jasmine describe output spec not found

I learned that this way is the best way to loop through the it() in a describe(), but it failed on me with "spec not found", and seems stop right before the for loop function, I wonder where did I do wrong?

Thanks!

describe('this is my looping test!', function() {
var input = [1,2,3];
var output = [10, 20, 30];

function test_my_times_ten(input, output) {
it('should multiply ' + input + ' by 10 to give ' + output, function() {
expect(input * 10).toEqual(output)
});
}

for(var x = 0; x < input.size; x++) {
test_my_times_ten(input[x], output[x]);
}
});

Answer

Actually someone did really smart thing like this, and it seems does the work!

Looping on a protractor test with parameters

var testParams = testConfig.testArray;

for (var i = 0; i < testParams.length; i++) {

  (function (testSpec) {
    it('write your test here', function () {
      //test code here
    });
  })(testParams[i]);

};