循环中的嵌套单元测试用例总是成功的

Nested Unit test case in a loop is always successful

我将一个测试用例从重复行重构为循环。但是,无论我在 testdata 对象中输入什么值,测试总是正确的。我错过了什么?

it('should calculate the correct price using the datetimepicker', function() {
    var testdata = {
    bundesweit: {
      sonder: '26.00',
      mini: '24.00',
      klein: '48.30',
      kompakt: '57.70',
      mittel: '66.90',
      transporter: '75.90'
    },
    lokal: {
      sonder: '18.35',
      mini: '18.35',
      klein: '23.85',
      kompakt: '28.35',
      mittel: '42.40',
      transporter: '42.40'
    }
  };

  var testcase = function (tariff, carClass, expectedPrice) {
    it('distance: ' + scope.rental.distance +
       ', tariff: ' + tariff + 
       ', carClass: ' + carClass, function () {
      scope.rate.tariff = tariff;
      scope.rate.carClass = carClass;
      expect(scope.price().toFixed(2)).toEqual(expectedPrice);
    });
  };

  for (var tariff in testdata) {
    for (var carClass in testdata[tariff]) {
      var expectedPrice = testdata[tariff][carClass];
      testcase(tariff, carClass, expectedPrice);
    }
  }
});

看起来你是这样做的...

require("should");
describe("test", function() {
    it('should pass', function(){

        "a".should.equal("a");

        var f = function() {
            it('should fail', function() {
                "a".should.equal("b");
            })
        };

        var i = 10;
        while(i--){
            f();
        }
    })
});

什么时候应该这样做...

describe("test", function() {
    describe('subsection', function(){

        var f = function() {
            it('should fail', function() {
                "a".should.equal("b");
            })
        };

        var i = 10;
        while(i--){
            f();
        }
    })
});

问题是 it 函数在其他 it 调用中被调用。