title: How to test .then(function in Unit Testing AgularJS with jasmine
body: <p>I am not clear how to use SpyOn in Unit Testing...</p>
  
  <p>I have the following controller</p>
  
  <pre><code>(function () {
      'use strict';
      angular.module('otpConfigureDatasets').controller('otpActivityCardController', otpActivityCardController);
  
      otpActivityCardController.$inject = ['$location', '$state', 'otpWebMapApp', 'otpWMDeltaTracker', 'otpWMStateCache', '$scope', '$timeout', 'otpActivityCardService', 'otpControlCenterData'];
  
      function otpActivityCardController($location, $state, otpWebMapApp, otpWMDeltaTracker, otpWMStateCache, $scope, $timeout, otpActivityCardService, otpControlCenterData) {
          var vm = this;
  
          vm.cards = [];
  
          otpActivityCardService.getActivityCards().then(function (resolve) {
              vm.cards = resolve;
          });
  
          //.....Some code ....
  
  })();
  </code></pre>
  
  <p>I need to test the GetActivityCards().then(function ...</p>
  
  <p>I tried test it using the code below  </p>
  
  <pre><code>'use strict';
  
  describe('Test controller (activityCard) in Page MyDatasets', function() {
  
  var MainCtrl, $state, scope, otpWebMapApp, otpWMDeltaTracker, otpWMStateCache, otpActivityCardService, otpControlCenterData;
  var card;
  
  beforeEach(function() {
      module('otpConfigureDatasets');
  });
  
   beforeEach(inject(function ($controller, $rootScope, _$state_, _otpWebMapApp_, _otpWMDeltaTracker_, _otpWMStateCache_, _otpActivityCardService_, _otpControlCenterData_) {
      scope = $rootScope.$new();
      scope.$parent = { $parent: { menuParentGroupClick: function menuParentGroupClick() { } } };
      MainCtrl = $controller('otpActivityCardController', {
          $scope: scope
      });
      otpWebMapApp = _otpWebMapApp_;
      otpWMDeltaTracker = _otpWMDeltaTracker_;
      otpWMStateCache = _otpWMStateCache_;
      otpActivityCardService = _otpActivityCardService_;
      otpControlCenterData = otpControlCenterData;
  }));
  
  it('Test Function', function() {
  
      spyOn(otpActivityCardService, 'getActivityCards');
  
      expect(otpActivityCardService.getActivityCards).toHaveBeenCalled();
  });
  
  });
  </code></pre>
  
  <p>But I am getting this error: </p>
  
  <pre><code>Expected spy getActivityCards to have been called.
  Error: Expected spy getActivityCards to have been called.
  </code></pre>
  
  <p>What is wrong? </p>