Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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]);
  }
});
like image 994
Ezeewei Avatar asked Feb 09 '23 05:02

Ezeewei


2 Answers

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]);

};
like image 139
Ezeewei Avatar answered Feb 11 '23 17:02

Ezeewei


i think the real problem is "input.size" at line "for(var x = 0; x < input.size; x++) {" . there is no such thing called "input.size". try input.length and your test will run as expected

like image 27
cppython Avatar answered Feb 11 '23 17:02

cppython