title: Testing promise in Jasmine and not resolving- getting Expected undefined to be object
body: <p>I am new to testing and I am testing some angular code with jasmine. The mock promise I have created isn't resolving.  Here is the block of code that I am testing:</p>
  
  <pre><code>    $scope.init = function() {
      EngageService.getGrouping($stateParams.gid).then(function(res) {
        $scope.grouping = res.data;
        $scope.parent_id = $scope.grouping.parent != null ? $scope.grouping.parent.id : null;
        $scope.startDate = $scope.grouping.startDate ? new Date($scope.grouping.startDate) : new Date()
        $scope.endDate = $scope.grouping.endDate ? new Date($scope.grouping.endDate) : new Date()
        $scope.nda = $scope.grouping.nda == "No" ? false : true;
        $scope.grouping.invitation = $scope.grouping.invitateOnly == true ? 'true' : 'false';
        $scope.canManageGrouping = UserService.memberships[$scope.grouping.id].role.canManageGrouping;
        $scope.canCreateGroup = UserService.memberships[$scope.grouping.id].role.canCreateGroup;
      })
      EngageService.getProjects().then(function(res) {
        $scope.projects = res.data.rows;
      })
    }
  </code></pre>
  
  <p>and here is the code for testing the promise</p>
  
  <pre><code>describe('Tests for WorkspaceEdit', functio
    var getGroupingPromise;
  
    beforeEach(function() {
      module('iq4App');
      return inject(function($injector) {
        this.EngageService = {
          getGrouping: function(gid) {
            getGroupingPromise = $q.defer();
            console.log(getGroupingPromise.promise)
            return getGroupingPromise.promise;
          }
        };
        this.scope = this.rootScope.$new();
        this.scope.$digest();
      });      '$upload': this.upload,
          'ResourceService': this.ResourceService,
          'MatchService': this.MatchService
        });
        this.scope.$digest();
      });
  
  
    });
  
  
        });
  
        it('should set stuff on init', function() {
  
          var fakeData = {
            data: {
              parent: {
                id: 3
              }
            }
          }
  
          this.scope.init();
          this.scope.$digest();
          getGroupingPromise.resolve(fakeData.data)
          expect(this.scope.grouping).toBe(fakeData.data);
  
  
        })
  
      });
  </code></pre>
  
  <p>I am trying to resolve some fake data to $scope.grouping but the data is resolving as undefined.  I know the promise is being created from my console.log in the getGrouping method in this.EngageService.  I've stripped out a lot of code that I didn't think was relevant but let me know if you want more detail.</p>
  
  <p>Thank you!</p>