2015-02-09 93 views
0

你會如何測試這個角度測試指令?測試一個角度js指令?

$scope.cancel = function() { 
      $('#pp_bsktexit').modal('show'); 
}; 

這樣的事情,我可以測試,它似乎並沒有太:

VAR nextScreenPath = 'C_HIST';

$scope.goBack = function() {     
      //sessionService.save($scope.sessionData);    
      $location.path(nextScreenPath); 
} 

和測試:

it('should return location path as nextScreenPath', function(){ 
      var nextScreenPath = 'C_HIST'; 
      expect($location.path()).toEqual(''); 
      scope.goBack(); 
      expect($location.path()).toEqual('/' + nextScreenPath); 

}); 

,但我不能完全轉移邏輯/知識測試原始查詢。任何人有任何想法?我需要嘲笑一些東西嗎?

回答

0

所以它似乎是你直接使用jQuery,這使得嘲笑有問題。

你應該做的是改用angular.element,如果它存在,它會在後臺自動使用jQuery。

然後在您的測試指令,你會一般使用間諜:

spyOn(元素, '')。

有幾個spyOn方法,用於返回固定值或調用僞造函數。看看間諜的茉莉花文檔:

http://jasmine.github.io/2.0/introduction.html#section-Spies