2015-01-21 8 views
5

을 비교하고, 나는 그들의 뺄셈이 코드 1.각도기 - 나는 두 숫자를 계산하는거야 내 프로그램에서 번호

동일 있는지 확인하려면 :

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

지금까지이 좋다 - 숫자가 나옵니다. 문제는 다음 온다 :

Expected NaN to equal 1. 

어떤 생각 :

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

는이 오류를 받고 있어요?

답변

4

모두 firstCountsecondCount을 필요 약속를 해결하기 위해 다음과 같습니다

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); 
    }) 
}); 
+0

나는 여전히 '약속'의 개념을 이해하려고 노력하고 있지만 작동합니다! 고마워. – user2880391

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); 
}) 

});

0

절대적으로 옳은 일을하고 있습니다. 그러나 비교하기 전에 결과 값이 숫자 유형인지 확인하십시오.

예 -이

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

나서 기대 조건에 대해 동작을 수행한다.