如何使用jasmine对modalInstance.close()进行spyon

时间:2016-04-28 09:59:54

标签: angularjs jasmine

这是我的js文件代码

  $scope.close = function () {
            modalInstance.close();
      };





unit test case for the js code

beforeEach(inject(function($rootScope) {
var modalInstance = { close: function() {}, dismiss: function() {} };


$controller('BusinessRuleEditCtrl',
       {
           $scope: scope,
           dataFactory: mockdataFactory,
           $modal: modal,
           modalInstance:modalInstance
       });


  }));
        it(' scope.close () functionality is checked ', function () {
            scope.close();
            spyOn(modalInstance, 'close').toHaveBeenCalled();
        });

当我尝试运行此规范时,我收到错误“无法读取属性'关闭'未定义”。任何建议都将受到赞赏....提前感谢。

0 个答案:

没有答案