2014-09-23 1 views
0

나는 검도를 분류 할 수있는 기존 사례가 있고 카르마와 재스민을 사용하여 힌트 기능을 테스트하려고합니다. Kendo Sortable로 드래그 이벤트를 에뮬레이트하여 힌트 기능을 호출하는 방법에 대한 아이디어가 있습니까?Kendo Sortable + 카르마 : 단위 테스트 힌트 기능

$element.find("#sortable-container").kendoSortable({ 
    axis: "none", 
    cursor: "move", 
    container: "#sortable-container", 
    hint: function (element) { //this is not called and is messing with my karma coverage 
     var elementHint = element.clone(); 

     elementHint.find('[ng-transclude=""]').removeAttr("ng-transclude"); 
     elementHint.find(".hw-closeable").removeClass("hw-closeable"); 

     return elementHint.addClass("sortable-tooltip"); 
    } 
}); 

답변

0

단위 테스트의 경우 힌트 기능을 수동으로 호출하면 충분했습니다. 나는 통합 테스트를 위해 좀 더 애호가가 필요하다는 데 동의한다.

angular.module('appSample').directive('sortableDiv', function() { 
    return { 
     restrict: 'A', 
     transclude: true, 
     templateUrl: 'src/widgets/sortable-div/sortable-div.html', 
     controller: function ($scope, $element) { 
      $element.find("#sortable-container").kendoSortable({ 
       axis: "none", 
       cursor: "move", 
       container: "#sortable-container", 
       hint: function (element) { 
        return element.clone().addClass("sortable-tooltip"); 
       } 
      }); 
     } 
    }; 
}); 

지침 HTML을

지침

<div id="sortable-container" class="row sortable-container" ng-transclude></div> 

카르마 테스트

을 :

내 코드는 다음과 같습니다

function sortableDiv() { 
    var el = angular.element('<div sortable-div><div id="sort1">Sort me!</div> <div id="sort2">Sort me again!</div></div>'); 

    compile(el)(scope); 

    scope.$digest(); 
    timeout.flush(); 

    return el; 
} 

it('should hint a sortable div', function() { 

    var el = sortableDiv(); 

    var elHint = el.find("#sortable-container").data("kendoSortable").options.hint(el.find("#sort1")); 

    expect(elHint.attr("class")).toContain("sortable-tooltip"); 
});