title: Angularjs promise not being resolved in unit test
body: <p>I am using jasmine to unit test an angularjs controller that sets a variable on the scope to the result of calling a service method that returns a promise object:</p>
  
  <pre><code>var MyController = function($scope, service) {
      $scope.myVar = service.getStuff();
  }
  </code></pre>
  
  <p>inside the service:</p>
  
  <pre><code>function getStuff() {
      return $http.get( 'api/stuff' ).then( function ( httpResult ) {
          return httpResult.data;
      } );
  }
  </code></pre>
  
  <p>This works fine in the context of my angularjs application, but does not work in the jasmine unit test.  I have confirmed that the "then" callback is executing in the unit test, but the $scope.myVar promise never gets set to the return value of the callback.</p>
  
  <p>My unit test:</p>
  
  <pre><code>describe( 'My Controller', function () {
    var scope;
    var serviceMock;
    var controller;
    var httpBackend;
  
    beforeEach( inject( function ( $rootScope, $controller, $httpBackend, $http ) {
      scope = $rootScope.$new();
      httpBackend = $httpBackend;
      serviceMock = {
        stuffArray: [{
          FirstName: "Robby"
        }],
  
        getStuff: function () {
          return $http.get( 'api/stuff' ).then( function ( httpResult ) {
            return httpResult.data;
          } );
        }
      };
      $httpBackend.whenGET( 'api/stuff' ).respond( serviceMock.stuffArray );
      controller = $controller( MyController, {
        $scope: scope,
        service: serviceMock
      } );
    } ) );
  
    it( 'should set myVar to the resolved promise value',
      function () {
        httpBackend.flush();
        scope.$root.$digest();
        expect( scope.myVar[0].FirstName ).toEqual( "Robby" );
      } );
  } );
  </code></pre>
  
  <p>Also, if I change the controller to the following the unit test passes:</p>
  
  <pre><code>var MyController = function($scope, service) {
      service.getStuff().then(function(result) {
          $scope.myVar = result;
      });
  }
  </code></pre>
  
  <p>Why is the promise callback result value not being propagated to $scope.myVar in the unit test?  See the following jsfiddle for full working code <a href="http://jsfiddle.net/s7PGg/5/" rel="noreferrer">http://jsfiddle.net/s7PGg/5/</a></p>