如何测试Angular / Jasmine中是否正确打开$ modal?

时间:2015-09-16 08:31:45

标签: javascript angularjs jasmine

有以下代码:

$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 });
  }));

});

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

1 个答案:

答案 0 :(得分:0)

您可以测试是否已调用方法open:

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