【问题标题】:How do i check a count value in chai-as-promised?如何检查 chai-as-promised 中的计数值?
【发布时间】:2015-05-14 14:29:11
【问题描述】:
我使用 cucumber 和 chai-as-promised 作为断言库。检查计数值的正确方法是什么。我使用equal,但只有在将字符串转换为整数后才有效。有没有办法直接断言整数值?
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);
});
【问题讨论】:
标签:
chai
cucumberjs
chai-as-promised
【解决方案1】:
如果你真的想要,我相信你可以通过使用 Chai 的 satisfy() 方法和 JavaScript 强制来绕过 parseInt(),如下所示。不过,我个人更喜欢您当前使用的方法,因为它更容易理解,而且强制转换可能很棘手。
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);
});