title: Angular Test does not call a promise callback
body: <p><strong>Environment:</strong></p>
  
  <ul>
  <li>Angular 1.5.8</li>
  <li>Unit Tests with Karma/Jasmine</li>
  </ul>
  
  <p>This is my controller, which aims to get a value from $stateParams and uses that, to perform a DELETE request, later on.
  Right now  it should ask the user, wether to delete the object.
  This is done with a sweetalert.</p>
  
  <p>I have removed ngdoc comments and arbitrary SWAL config.</p>
  
  <p><strong><em>ClientDeleteController.js:</em></strong></p>
  
  <pre><code>angular.module('app.data').controller('ClientDeleteController', [
    '$stateParams', '$q',
    function ($stateParams, $q) {
      'use strict';
  
      var vm = this;
      vm.clientId = $stateParams.id;
      vm.promptDeferred = null;
  
      vm.prompt = function () {
  
        // create promise
        var d = $q.defer();
        vm.promptDeferred = d;
  
        // create prompt
        swal({ .... }, vm.swalCallback);
      };
  
      vm.swalCallback = function (confirmed) {
        if (confirmed) {
          console.info('resolving...');
          vm.promptDeferred.resolve();
        } else {
          console.info('rejecting...');
          vm.promptDeferred.reject();
        }
      };
  
      vm.delete = function () {
        vm.prompt();
        vm.promptDeferred.promise.then(vm.performDelete);
      };
  
      vm.performDelete = function () {
        console.info('performing');
      };
    }]);
  </code></pre>
  
  <p>This is the test suite:</p>
  
  <p><strong><em>ClientDeletecontrollerSpec.js</em></strong></p>
  
  <pre><code>describe('Controller:ClientDeleteController', function () {
  
    var controller
      , $httpBackend
      , $rootScope
      , $controller
      , scope
      , $q
      , $stateParams = {id: 1}
      , resolvePromise = true
      ;
  
    swal = function (options, callback) {
      console.info('i am swal, this is callback', callback+'', resolvePromise);
      callback(resolvePromise);
    };
  
    beforeEach(function () {
      module('app');
      module('app.data');
      module('ui.bootstrap');
      module(function ($provide) {
        $provide.service('$stateParams', function () {
          return $stateParams;
        });
      });
  
      inject(function (_$controller_, _$rootScope_, _$q_) {
        $controller = _$controller_;
        $rootScope = _$rootScope_;
        $q = _$q_;
  
        scope = $rootScope.$new();
  
        controller = $controller('ClientDeleteController', {$scope: scope, $q: $q});
  
      });
    });
  
    describe('basic controller features', function () {
      it('should be defined', function () {
        expect(controller).toBeDefined();
      });
      it('should get the client id from the state params', function () {
        expect(controller.clientId).toBeDefined();
        expect(controller.clientId).toEqual($stateParams.id);
      });
    });
  
    fdescribe('client delete process', function () {
  
      it('should ask the user if he really wants to delete the client', function () {
        spyOn(controller, 'prompt').and.callThrough();
        controller.delete();
        expect(controller.prompt).toHaveBeenCalled();
      });
  
      it('should create a promise', function () {
        controller.prompt();
        expect(controller.promptDeferred).toBeDefined();
      });
  
      it('should delete when the user clicked yes', function () {
        spyOn(controller, 'performDelete').and.callThrough();
        controller.delete();
        expect(controller.performDelete).toHaveBeenCalled();
      });
  
      it('should not delete when the user clicked no', function () {
        spyOn(controller, 'performDelete').and.callThrough();
        resolvePromise = false;
        controller.delete();
        expect(controller.performDelete).not.toHaveBeenCalled();
      });
    });
  
  });
  </code></pre>
  
  <p>The test <code>should delete when the user clicked yes</code> fails, the test <code>should not delete when the user clicked no</code>returns a false positive.</p>
  
  <p>The <code>console.info(...)</code> within the swal mock logs the correct callback function. The logs in the function itself are also logged, which tells me, the callback is fired.
  Since in the next line, I call either <code>vm.promptDeferred.resolve()</code> resp. <code>.reject()</code>, I expect the call to actually happen.</p>
  
  <p>Nonetheless, the test result is <code>Expected spy performDelete to have been called.</code>.</p>
  
  <p>I have mocked swal in another test the same way and it works fine.
  I don't get why the promise won't be resolved.</p>
  
  <p>Notice: When I don't store the promise directly on the controller but return it from <code>prompt()</code> and use the regular <code>.prompt().then(...)</code>, it won't work either.
  The logs are the same and I like to split functions as much as possible, so it is easier to understand, easier to test and to document.</p>
  
  <p>There are hundreds of other tests in this application but I can't see, why this one won't work as expected.</p>
  
  <p>Thank you for any insight.</p>