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 badges
Add a ment  | 

3 Answers 3

Reset to default 4

Both 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