ey dee ey em
ey dee ey em

Reputation: 8603

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

Upvotes: 4

Views: 11711

Answers (2)

cppython
cppython

Reputation: 1279

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

Upvotes: 1

ey dee ey em
ey dee ey em

Reputation: 8603

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

};

Upvotes: 7

Related Questions