簡體   English   中英

如何測試$ modal是否在Angular / Jasmine中正確打開?

[英]How to test if $modal is opened in Angular/Jasmine properly?

有以下代碼:

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

});

但是我不明白如何測試模式窗口是否已打開。 預先感謝!

您可以測試是否已調用open方法:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM