title: Testing angular service that is also a promise
body: <p>I'm working with <code>browserify</code> to bundle up an angular service. I'm using <code>jasmine</code> to write tests for this service, which is defined like:</p>
  
  <pre><code>angular
    .module('Client', [])
    .factory('client', ['url', 'otherService', '$http', '$log', client])
  
  function client (url, otherService, $http, $log) {
    $log.debug('Creating for url %s', url)
    var apiRootPromise = $http.get(url).then(function (apiRoot) {
      $log.debug('Got api root %j', apiRoot)
      return otherService.stuff(apiRoot.data)
    })
    return Object.assign(apiRootPromise, otherService)
  }
  </code></pre>
  
  <p>The following test suite:</p>
  
  <pre><code>describe('test client', function () {
      beforeEach(function () {
        angular.mock.module('Client')
        angular.mock.module(function ($provide) {
          $provide.value('url', 'http://localhost:8080/')
        })
      })
  
      it('should connect at startup', angular.mock.inject(function (client, $rootScope, $httpBackend) {
        $rootScope.$apply()
        $httpBackend.flush()
        expect(client).toBeDefined()
      }))
    })
  </code></pre>
  
  <p>Throws a <code>TypeError: undefined is not a constructor</code> on <code>(evaluating Object.assign(apiRootPromise, otherService)')</code>. I'm not sure what's happening here, but my best guess is Angular is not injecting properly the dependent service or not returning the <code>$http</code> promise.</p>