title: Angular $q.when is not resolved in Karma unit test
body: <p>I use <strong>$q.when</strong> to wrap around other lib promises. 
  It works like a charm but when i try to run it inside Karma the promise failes to resolve (<strong>done()</strong> is never executed) even if I ran <strong>$digest</strong> and even after timeout.
  Here is sample code: </p>
  
  <pre><code>describe('PouchDB', function () {
  var $q, $rootScope;
  
  beforeEach(inject(function (_$rootScope_, _$q_) {
      $rootScope = _$rootScope_;
      $q = _$q_;
  }));
  
  it("should run", function (done) {
  
      function getPromise() {
          var deferred = Q.defer();
  
          deferred.resolve(1);
  
          return deferred.promise;
      }
  
      $q.when(getPromise())
          .then(function () {
              done();   // this never runs
          });
  
      $rootScope.$digest();
  });
  </code></pre>
  
  <p>Why? What is the cause of this? I really cannot get it.</p>
  
  <p><strong>Update (workaround)</strong></p>
  
  <p>I do not understand why $q.when is not resolved in Karma - it has something with nextTick function but I cannot debug the problem.
  Instead I ditched $q.when and wrote simple function that converts PouchDB (or any other like Q) to $q:</p>
  
  <pre><code>.factory('$utils', function ($q, $rootScope) {
    return {
      to$q: function (promise) {
        var deferred = $q.defer();
  
        promise.then(function (result) {
          deferred.resolve(result);
          $rootScope.$digest();
        });
  
        promise.catch(function (error) {
          deferred.reject(error);
          $rootScope.$digest();
        });
  
        return deferred.promise;
      }
    }
  })
  </code></pre>