2017-09-28 7 views
0

각도기를 사용하여 오이 테스트 단계를 만들고 싶었지만 '2019'가 쓸 수 없다는 예상 단계가있었습니다. . 여기 내 소스 코드는 다음 기대 (yearString) .to.eventually.contain에서TypeError '2019'는 변경할 수 없습니다.

 this.Then(/^I check that the calculated year from the current month\(if current month >= 6 ==> current year = current year \+ 2,else current year = current year \+ 1\)$/,function(callback) { 

      var actualDate=new Date(); 
      var actualYear=actualDate.getFullYear(); 
      var actualMonth=actualDate.getMonth()+1; 
      //expect(targetAmountPO.getYesInflationLabel().isDisplayed()).eventually.to.equal(true).then(callback); 
      targetAmountPO.getYesInflationLabel().isDisplayed().then(function() { 
       targetAmountPO.getYesInflationCorrectionAnswer().isSelected().then(function(){ 
        targetAmountPO.getYesInflationLabel().getAttribute("outerText").then(function(text,callback){ 
         //console.log(text); 
         var splittedString=text.split(":"); 
         //console.log(splittedString[1]); 
         if(actualMonth>=6) 
         { 
          actualYear+=2; 
          var yearString=actualYear.toString(); 
          console.log(yearString); 
          expect(yearString).to.eventually.contain(splittedString[1]).and.notify(callback); 

          //console.log(actualYear); 

         } 
         else 
         { 
          expect(actualYear+1).to.include(splittedString[1]).and.notify(callback); 

         } 

       }) 

       }) 

      }) 


     }) 

(splittedString [1]) (콜백) and.notify;

나는 '2019'를 얻을 수 없습니다. yearString은 2019가 좋습니다. 하지만 왜 그럴 수없는거야?

도와 주시겠습니까?

답변

1

제대로 방금

expect(yearString).to.contain(splittedString[1]) 
callback() 
같은 약속 주장과 같은 차이의 주장이 아니라 차이를 사용할 수 있도록 yearStringsplittedString의 값은 단지 실제 값이 아니라 약속이다 getAttribute("outerText")에 의해 반환 약속을 처리했듯이

그리고 어설 션이 실제로 확인을하기 전에 콜백하지 않도록 테스트 할 수 있습니다.

+0

감사합니다. 로스. 약속을 이해해야합니다, beacuse 저는 JAVA 개발자이지만 AngularJS E2E 테스트를 받았습니다. – user3654435