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

Eze*_*wei 3 javascript unit-testing jasmine jasmine-node

我了解到这种方式是在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]);
  }
});
Run Code Online (Sandbox Code Playgroud)

Eze*_*wei 6

实际上有人做了这样的聪明的事情,似乎工作!

循环使用参数的量角器测试

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

};
Run Code Online (Sandbox Code Playgroud)