title: Unit testing angular $modal.result.then()
body: <p>I am writing unit tests for a controller and I stuck on testing <code>$modal</code>.
  I am confusing how could I unit test code inside <code>newModal.result.then()</code>? </p>
  
  <p>Here is the code:</p>
  
  <pre><code> angular.module('myModule')
         .controller('myCtrl', function($modal){
             $scope.myFunction = function(){
                 var newModal = $modal.open({
                     templateUrl: 'path.html',
                     controller: 'modalController',
                     backdrop: 'static',
                     resolve: {
                        message: function (){return 'some messages';}
                     }
                 });
                 newModal.result.then(function(type){
                     $scope.type = type;
                 });
             };
         });
  </code></pre>
  
  <p>Here is what I have right now:</p>
  
  <pre><code>describe('Testing modalController', function(){
      var $scope,ctrl,$modal;     
      var fakeMsg = {
              result: {
                  then: function(confirmCallback, cancelCallback) {
                      this.confirmCallBack = confirmCallback;
                      this.cancelCallback = cancelCallback;
                  }
              },
              close: function(item) {
                  this.result.confirmCallBack(item);
              },
              dismiss: function(type) {
                  this.result.cancelCallback(type);
              }
          };        
  
  
      beforeEach(module('myModule'));
  
      beforeEach(inject(function(_$rootScope_, $controller,_$modal_){
          $rootScope = _$rootScope_;
          $scope = $rootScope.$new();
          ctrl = $controller('myCtrl', {$scope: $scope});};
          $modal = _$modal_;
      }));
     it("should open modal", function() {
          spyOn($modal, 'open').andReturn(fakeMsg);
          $scope.myFunction();
          $rootScope.$apply();
          expect($modal.open).toHaveBeenCalled();
      });    
  });
  </code></pre>