Testing AngularUI Bootstrap modal instance controller

后端 未结 4 790
醉话见心
醉话见心 2020-12-05 07:32

This is a somewhat of a follow-on question to this one: Mocking $modal in AngularJS unit tests

The referenced SO is an excellent question with very useful answer. Th

4条回答
  •  天命终不由人
    2020-12-05 07:37

    Follow below given steps:

    • Define stub for ModalInstance like give below

              uibModalInstanceStub = {
                  close: sinon.stub(),
                  dismiss: sinon.stub()
              };
      
    • Pass the modal instance stub while creating controller

          function createController() {
              return $controller(
                  ppcConfirmGapModalComponentFullName,
                  {
                      $scope: scopeStub,
                      $uibModalInstance: uibModalInstanceStub
                  });
          }
      });
      
    • Stub methods close(), dismiss() will get called as part of the tests

      it('confirm modal - verify confirm action, on ok() call calls modalInstance close() function', function() { action = 'Ok'; scopeStub.item = testItem; createController(); scopeStub.ok(); });

提交回复
热议问题