title: Need help writing an Angular TypeScript Jasmine test for an Angular Service
body: <p>I am attempting to write a test for an Angular Service using TypeScript. I'll be honest and say I have no idea what I'm doing as this is the first test I have ever written so any help would be appreciated. </p>
  
  <p>What I have so far gives the following error:
  TypeError: 'undefined' is not an object (evaluating 'this.httpAccessor.get(requestUrl).then')</p>
  
  <p>Here is the service I am attempting to test:</p>
  
  <pre><code>/// &lt;reference path="../../../typings/_references.ts" /&gt;
  
  module app.service {
    'use strict';
  
    export interface IAvailability {
      getAvailability(requirements: app.Requirements): ng.IPromise&lt;any&gt;;
    }
  
    export class Availability implements IAvailability {
  
      static $inject = ['$filter', 'Service.HttpResourceAccessor'];
  
      /**
       * Constructor.
       */
      constructor(private $filter: ng.IFilterService,
        private httpAccessor: app.service.IHttpResourceAccessor) {
      }   
  
      /**
       *  Returns availability promise
       */
      getAvailability(requirements: app.Requirements): ng.IPromise&lt;any&gt; {
  
        /**
        * Generate the request url using the requirements
        */
        var requestUrl = this.generateRequestUrlFromRequirements(requirements);
  
        return this.httpAccessor.get(requestUrl).then((response) =&gt; {
  
          var availability: app.ITripAvailability&lt;app.ITripAvailability&gt;response;
          return availability;
        });
      }
  
      /**
      * Builds the request url using the requirements
      */
      private generateRequestUrlFromRequirements(requirements: app.Requirements): string {
  
        //The request string that will be returned after building
        var requestUrl: string = '';
        var baseAddress = 'http://localhost:8080/';
  
        //Code emitted as this just builds a string and works fine
  
        return requestUrl;
      }
    }
  
    angular.module('app.service')
      .service('Service.Availability', Availability);
  }
  </code></pre>
  
  <p>Here is the test so far:</p>
  
  <pre><code>/// &lt;reference path="../../../../typings/_references.ts" /&gt;
  /// &lt;reference path="../../../../typings/angularjs/angular-mocks.d.ts" /&gt;
  /// &lt;reference path="../../../../typings/jasmine/jasmine.d.ts" /&gt;
  
  module app.service {
  
    describe("app.service.IAvailability", () =&gt; {
      'use strict';
  
      var $filter: ng.IFilterService;
      var mockAvailabilityService: app.service.Availability;
      var mockHttpAccessor: app.service.IHttpResourceAccessor;
      var requirements: app.Requirements;
  
      beforeEach(() =&gt; {
        angular.mock.module('app');
      });
  
      beforeEach(() =&gt; {
        angular.mock.module('app.service');
      });
  
      /**
      * Pre-test function before the test is executed
      */
      beforeEach(() =&gt; {
  
        requirements = new app.Requirements();
  
        angular.mock.inject((_$filter_: ng.IFilterService) =&gt; {
          $filter = _$filter_;
  
          mockHttpAccessor = &lt;app.service.IHttpResourceAccessor&gt;jasmine.createSpyObj(
            "httpAccessor", ["get"]);
  
          mockAvailabilityService = new app.service.Availability(
            &lt;ng.IFilterService&gt;$filter, 
            &lt;app.service.IHttpResourceAccessor&gt;mockHttpAccessor);
        });
  
      });
  
      it('Should call httpAccessor.get', () =&gt; {
        mockAvailabilityService.getAvailability(tripRequirements);
        expect(mockHttpAccessor.get).toHaveBeenCalled();
      });
  
      //How do I check if promise has been resolved?
    });
  }
  </code></pre>