5

在我的程序中,我正在计算两个数字,我想确保它们的减法等于 1。

这是代码:

var firstCount=element.all(by.repeater('app in userApps')).count();
var secondCount=element.all(by.repeater('app in userApps')).count();

到目前为止一切都很好——我得到了数字。问题来了:

var sub=secondCount-firstCount;
expect(sub).toEqual(1);

我收到此错误:

Expected NaN to equal 1.

任何想法?

4

3 回答 3

4

firstCount和都是需要解决secondCount承诺

element.all(by.repeater('app in userApps')).count().then(function (first) {
    element.all(by.repeater('app in userApps')).count().then(function(second) {
        expect(first - second).toEqual(1);
    })
});
于 2015-01-21T21:23:18.677 回答
0

可以只解决第一个承诺。量角器适应expect“理解”承诺。请参阅https://github.com/angular/protractor/blob/master/docs/control-flow.md#protractor-adaptationshttps://github.com/angular/protractor/issues/128

element.all(by.repeater('app in userApps')).count().then(function (first) {
    // Do any changes here...
    var second = element.all(by.repeater('app in userApps')).count();
    // Here expect() resolves 'second'
    expect(second).toEqual(first + 1);
})

});

于 2015-02-18T12:48:11.930 回答
0

你做的绝对正确。但在比较之前,请检查您的结果值是否为数字类型。

例子-

expect(sub).toEqual(jasmine.any(Number));

然后针对预期条件执行操作。

于 2017-10-03T06:47:36.863 回答