在 jasmine 中循环 it() 描述未找到输出规范

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

我了解到 this way 是在 describe() 中循环遍历 it() 的最佳方法,但它在我身上失败了 "spec not found",并且似乎在 for 循环之前停止了函数,请问我哪里做错了?

谢谢!

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

实际上有人做了这样非常聪明的事情,而且看起来很有效!

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

};

我认为真正的问题是 "input.size" 在第 "for(var x = 0; x < input.size; x++) {" 行。没有所谓的"input.size"。试试 input.length,你的测试会 运行 如预期的那样