2015-09-16 37 views
0

有下面的代码:

$scope.removePoint = function(point) { 
    $modal.open({ 
       templateUrl: 'templates/deleting_modal.html', 
       controller: 'DeletingPointModalController', 
       size: 'sm', 
       resolve: { 
       points: function() { 
        return $scope.points; 
       }, 
       point: function() { 
        return point; 
       } 
       } 
      }); 
}; 

我想测试一下:

describe('HomeController', function() { 
    beforeEach(module('app')); 

    var $scope; 

    beforeEach(inject(function(_$controller_, _$rootScope_){ 
    $scope = _$rootScope_.$new(); 
    _$controller_('HomeController', { $scope: $scope }); 
    })); 

}); 

但我不明白,如果模态窗口已经打开我如何测试。预先感谢!

回答

0

您可以测试方法打开已被称为:

describe('$scope.removePoint', function() {  
    it('should call $modal.open', function() { 
     spyOn($modal, 'open'); 
     $scope.removePoint(); 
     expect($modal.open).toHaveBeenCalled(); 
    }); 
});