title: Mocking asynchronous service function using angular/karma/jasmine
body: <p>The test in this code does not succeed.  I can't seem to successfully test the return of an asynchronous function.</p>
  
  <pre><code>describe('mocking services', function () {
  
      var someService, deferred;
  
      beforeEach(function () {
  
          module(function($provide){
              $provide.factory('someService', function($q){
                  return{
                      trySynch: function(){
                          return 33;
                      },
                      tryAsynch: function(){
                          deferred = $q.defer();
                          return deferred.promise;
                      }
                  };
              });
          });
  
          inject(function (_someService_) {
              someService = _someService_;
          });
      });
  
      it('should be able to test values from both functions', function () {
          expect(someService.trySynch()).toEqual(33);
  
          var retVal;
          someService.tryAsynch().then(function(r){
              retVal = r;
          });
          deferred.resolve(44);
          expect(retVal).toEqual(44);
      });
  
  });
  </code></pre>
  
  <p>When I run it I get the following error:</p>
  
  <pre><code>Chrome 36.0.1985 (Mac OS X 10.9.4) mocking services should be able to test values from both functions FAILED
          Expected undefined to equal 44.
          Error: Expected undefined to equal 44.
              at null.&lt;anonymous&gt; (/Users/selah/WebstormProjects/macrosim-angular/test/spec/services/usersAndRoles-service-test.js:34:24)
  </code></pre>
  
  <p>How can I make this test pass?</p>