我如何检查chai-as-promise中的计数值?

时间:2015-05-14 14:29:11

标签: chai cucumberjs chai-as-promised

我使用黄瓜和chai-as-promise作为断言库。检查计数值的正确方法是什么。我使用相等,但只有在将字符串转换为整数后才能工作。有没有办法直接断言整数值?

this.Then(/^the list should contain "([^"]*)" items$/, function (arg1, callback) {
       var count=parseInt(arg1);
      expect(element.all(by.repeater('item in list.items')).count()).to.eventually.equal(count).and.notify(callback);

  });

1 个答案:

答案 0 :(得分:0)

如果你真的想,我相信你可以通过使用Chai的parseInt()方法和JavaScript强制来绕过satisfy(),如下所示。但是,我个人更喜欢你目前使用的方法,因为它更容易理解,强制可能会很棘手。

this.Then(/^the list should contain "([^"]*)" items$/, function (arg1, callback) {
  expect(element.all(by.repeater('item in list.items')).count()).to.eventually.satisfy(function(count) { return count == arg1 } ).and.notify(callback);
});