2016-11-22 16 views
0

"무엇을하고 계십니까?"(필자는 [변경] 이전에는 통과했지만) 지금까지는 테스트가 실패했습니다. 달리 증명할 모든 노력에도 불구하고 명백한 등급이 존재합니다.클래스가 존재하지 않더라도 각성 된 hasClass가 true를 반환합니다.

컨텍스트 :

참가자의 목록을 나타낸다, 평가 또는 획득 할 수있는 각. 참가자의 부서 내에서 관련 (카테고리 별) 참가자가 요약되어 표시됩니다. 요약 참가자의 점수는 참가자 자신이 자신의 div를 통해 평가 될 때까지 표시되지 않습니다. 이 테스트는이 동작을 확인합니다.

테스트 :

it('related items are hidden until scored', function() { 

    expect(judgeService.entrants[2].rating.score).toBe(0); 

    var other = angular.element(element.find('.competition')[0]); 
    var score_container = other.find('div > div'); 
    expect(score_container.hasClass('ng-hide')).toBe(true); 

    judgeService.entrants[2].rating.score = 3; 
    scope.$digest(); 

    // We'll refer to this later 
    console.log('HTML: ' + other.html()); 
    console.log('CLASS: ' + score_container.attr('class')); 

    // failure here 
    expect(score_container.hasClass('ng-hide')).toBe(false); 
}); 

HTML :

 <div class="competition" 
      ng-repeat="other in item.related"> 
      <div> 
       {{ other.name }}<br/> 
       <!-- this becomes the div > div in the test --> 
       <score-block item="other" ng-show="other.rating.score"></score-block> 
      </div> 
     </div> 

출력 : hasClass (

LOG: 'HTML: 
      <div class="ng-binding"> 
       Andres<br> 
       <div class="ng-isolate-scope" ng-class="{error: vm.error}" item="other" ng-show="other.rating.score"> 
[ skippy bits ]' 

LOG: 'CLASS: ng-isolate-scope' 

그래, 좋아, 클래스는 ... 요소에 존재하지 왜 않습니다) 그것이라고 생각 하느냐?

[변경] 자식 당

이등분, 실패한 시작 시험 의한 변화는 무관 지정했다. 그러나 변경 사항이 직접적으로 관련 되더라도 hasClass()가 클래스를 부재로보고하는 방식을 모두 보지 못합니다.

업데이트 : jQuery 코드를 통해 파고

은 요소의 자식 요소 중 하나가 클래스 "가있는 경우 element.hasClass는 ("foo는 ")가 true를 돌려 것으로 보인다 (hasClass()이 설치된 경우 jQuery를 사용) foo "를 반환합니다. WTF, jquery?

답변

0

분명히 이것은 부모 요소에서 ng-hide 클래스가있는 자식으로 재귀하는 'div> div'선택기 때문에 발생합니다.

수정 :

var score_container = other.find('div > div').eq(0);