2015-01-09 3 views
1

시간이 걸리는 일종의 데이터 처리를 트리거하는 버튼이 있다고 가정 해 봅시다. 처리하는 동안 "Working ...", "Working very hard ...", "Almost there ..."등과 같은 메시지를 표시하여 사용자 위치를 알리고 싶습니다. 모든 메시지 처리가 완료되기 전에 하나씩 차례로 나타납니다. 과제는 각도기로이 시나리오를 점검하는 것입니다.각도기를 사용하여 일련의 비동기 업데이트를 테스트 하시겠습니까?

<div ng-controller="AppController"> 
    <p>{{message}}</p> 
    <button type="button" ng-click="go()">Go!</button> 
</div> 
... 
<script> 
    angular.module('app', []) 
    .controller("AppController", function($scope, $timeout) { 
    $scope.message = ""; 
    $scope.go = function() { 
     $scope.message = "Working..."; 
     $timeout(function() { 
     $scope.message = "Working very hard..."; 
     $timeout(function() { 
      $scope.message = "Almost there..."; 
      $timeout(function() { 
      $scope.message = "Done!!!"; 
      }, 1000); 
     }, 1000);   
     }, 1000); 
    }; 
    }); 
</script> 

나는이 문제가 정기적으로 단위 테스트 (재스민)와 테스트, 아직의이 $timeout 호출이를 통해 백엔드로 전송 실제로 비동기 업데이트 척 수 있도록 비교적 쉽게 이해 :

그래서, 여기에 예제 코드는 websocket.

각도기로이 업데이트 순서를 어떻게 테스트 할 수 있습니까? 이 같은

똑 바른 방법 :

expect(element(by.binding('message')).getText()).toEqual('Working...'); 
expect(element(by.binding('message')).getText()).toEqual('Working very hard...'); 

이 작동하지 않습니다. 이해할 수

Expected 'Working very hard...' to equal 'Working...'. 

, 나는 보류중인 모든 일을 이동하기 전에 끝날 때까지 각도기 그냥 대기하는 가정 내 경우에는 테스트가 실패합니다.

내가 생각할 수있는 한 가지 접근법은 명시 적으로 DOM을 폴링하여 요소 콘텐츠가 변경되는 시점을 모니터링하는 것입니다. 이것은 피하고 싶습니다. 더 좋은 옵션이 있습니까?

답변

4

당신은 새로운 기능에 시도를 제공 할 수 있습니다 : expected conditions은 (14 시간 전 하였다) :

var EC = protractor.ExpectedConditions; 

var message = element(by.binding('message'); 

browser.wait(EC.textToBePresentInElement(message, 'Working...'), 1000); 
browser.wait(EC.textToBePresentInElement(message, 'Working very hard...'), 1000); 
browser.wait(EC.textToBePresentInElement(message, 'Almost there...'), 1000); 
browser.wait(EC.textToBePresentInElement(message, 'Done!!!'), 1000); 
+0

textToBePresentInElement 내 경우에 작동하지 않습니다. http://stackoverflow.com/questions/41829169/protractor-wait-command-is-not-able-to-wait-for-the-bootstarp-modal-to-appear를 참조하십시오. –

관련 문제