title: How to resolve $q.all promises in Jasmine unit tests?
body: <p>My controller has code like below:</p>
  
  <pre class="lang-js prettyprint-override"><code>$q.all([qService.getData($scope.id), dService.getData(), qTService.get()])
  .then(function (allData) {
    $scope.data1 = allData[0];
    $scope.data2 = allData[1];
    $scope.data3 = allData[2];
  });
  </code></pre>
  
  <p>And in my unit tests i am doing something like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>beforeEach(inject(function($rootScope, $q, $location){// and other dependencies... 
    qServiceSpy = spyOn(_qService, 'getData').andCallFake(function () {
      var data1 = {
        id: 1,
        sellingProperty: 1,
      };
      var d = $q.defer();
      d.resolve(data1);
      return d.promise;
    });
  
    dServiceSpy = spyOn(_dService, 'getData').andCallFake(function () {
      var data2 = [{ "id": "1", "anotherProp": 123 }];
      var d = $q.defer();
      d.resolve(data2);
      return d.promise;
    });
    qTServiceSpy = spyOn(_qTService, 'get').andCallFake(function () {
      var data3 = [{ id: 0, name: 'Rahul' }];
      var d = $q.defer();
      d.resolve(data3);
      return d.promise;
    });
    rootScope = $rootScope;
  });
  </code></pre>
  
  <p>Now in my test i am checking if services are called and the data1, data2 are not undefined..</p>
  
  <pre class="lang-js prettyprint-override"><code>it('check if qService' got called, function() {
    expect(scope.data1).toBeUndefined();
    rootScope.$digest();
    expect(_quoteService.getQuote).toHaveBeenCalled();
  });
  it('check if "data1" is defined', function () {
    expect(scope.data1).toBeUndefined();
    rootScope.$digest();
    expect(scope.data1).toBeDefined();
  });
  </code></pre>
  
  <p>my problem is, this was working fine until i replaced my individual service calls in controller with q.all and in tests <code>scope.$apply</code> with <code>rootScope.$digest</code>. With q.all and <code>rootScope.$digest</code> (tried using <code>scope.$apply</code> as well) both tests fails with error:</p>
  
  <blockquote>
    <p>10 $digest() iterations reached. Aborting!</p>
  </blockquote>
  
  <p>if i remove <code>rootScope.$digest</code> then the promises never get resolves and tests fails saying </p>
  
  <blockquote>
    <p>expected undefined to be defined.</p>
  </blockquote>
  
  <p>Any help how should i unit tests code with <code>q.all</code>?</p>
  
  <p>came across <a href="https://groups.google.com/forum/#!msg/angular/icQGGKZy-Is/zwnmZZdfT-0J" rel="noreferrer">this post</a></p>
  
  <p>But that also doesn't help as i am already trying to use <code>$digest</code>.</p>