【问题标题】:Jasmine 2 Spec has no expectationsJasmine 2 Spec 没有任何期望
【发布时间】:2016-10-22 21:21:36
【问题描述】:

我有以下测试:

describe('when invoked', function() {
  it('should check something', function() {
    _.each(someData, function(obj, index) {
      expect(obj[index].lable).toBe('foo');
    });
  });
});

当我运行 Jasmine 2.2.0 时出现以下错误:

Spec 'SpecLabel function when invoked return value should check something' has no expectations.

我错过了什么吗?在 Jasmin 1.x 中,我们可以做到这一点。在 for each 甚至 for 循环中都有 expect。

如何解决这些类型的测试?这些情况的文档是什么? Jasmine 网站并不是很有帮助。

【问题讨论】:

    标签: javascript unit-testing testing jasmine grunt-contrib-jasmine


    【解决方案1】:

    一种快速的解决方法可以将您的测试重构为:

    describe('when invoked', function () {
        it('should check something', function () {
            var success = true;
            _.each(someData, function (obj, index) {
                success &= obj[index].lable === 'foo';
            });
            expect(success).toBeTruthy();
        });
    });
    

    【讨论】:

      猜你喜欢
      • 2019-07-22
      • 2019-08-01
      • 2018-01-16
      • 2017-06-28
      • 2019-04-13
      • 2012-11-11
      • 1970-01-01
      • 2012-05-01
      • 1970-01-01
      相关资源
      最近更新 更多