admin管理员组文章数量:1406308
In my program I'm calculating two numbers, and I want to make sure that subtraction of them equals 1.
this is the code:
var firstCount=element.all(by.repeater('app in userApps')).count();
var secondCount=element.all(by.repeater('app in userApps')).count();
so far it's good- I'm getting the numbers. the problem es next:
var sub=secondCount-firstCount;
expect(sub).toEqual(1);
I'm getting this error:
Expected NaN to equal 1.
any idea?
In my program I'm calculating two numbers, and I want to make sure that subtraction of them equals 1.
this is the code:
var firstCount=element.all(by.repeater('app in userApps')).count();
var secondCount=element.all(by.repeater('app in userApps')).count();
so far it's good- I'm getting the numbers. the problem es next:
var sub=secondCount-firstCount;
expect(sub).toEqual(1);
I'm getting this error:
Expected NaN to equal 1.
any idea?
Share Improve this question edited Jan 21, 2015 at 21:24 alecxe 475k127 gold badges1.1k silver badges1.2k bronze badges asked Jan 21, 2015 at 21:16 user2880391user2880391 2,8018 gold badges42 silver badges80 bronze badges3 Answers
Reset to default 4Both firstCount
and secondCount
are promises that are needed to be resolved:
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);
})
});
It's possible to resolve only the first promise. Protractor adapts expect
to "understand" promises. Refer https://github./angular/protractor/blob/master/docs/control-flow.md#protractor-adaptations and https://github./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);
})
});
You are doing absolutely right. But Before parison, Check whether your result value is number type or not.
Example-
expect(sub).toEqual(jasmine.any(Number));
Then perform an operation for expected conditions.
本文标签: javascriptProtractorcompare numbersStack Overflow
版权声明:本文标题:javascript - Protractor - compare numbers - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744992242a2636454.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论