title: How can I test a angular services that use current $location to get the current lo get the current host using jasmine
body: <p>I created a test with jasmine that check is the services that is giving me the endpoint of the API is working. I am getting the default value because the application in unit test in not running in localhost. So how can I mock that feature in mu unit test.</p>
  
  <p>Here is my unit test:</p>
  
  <pre><code>describe("EndpointService-&gt;", getApiEndPoint);
  
  function getApiEndPoint() {
  
      beforeEach(function () {
          module('app');
      });
  
      it("GetApiEndpointUriBaseOnCurrentHost", inject(function (endpointService) {
          //Arrange
          var expectedUriInLocalhostEnviroment = 'not recognized client host';
  
          //Act
          var uriEndPoint = endpointService.getApiEndpoint();
          //Assert 
          expect(uriEndPoint).toMatch(expectedUriInLocalhostEnviroment);
  
      }));
      };
  </code></pre>
  
  <p>This is my service. It is using <code>$location</code> to get the local host:</p>
  
  <pre><code>(function () {
      'use strict'
      var app = angular.module('app');
      app.factory('endpointService', endpointService);
  
      function endpointService($location) {
          return {
              getApiEndpoint: function () {
                  var endpoint = '';
                  var host = $location.host();
                  switch ($location.host()) {
                      case 'localhost': endpoint = 'http://localhost:59987/'; break;
                      case 'projectDev': endpoint = 'http://project.com'; break;
                      default: endpoint = 'not recognized client host'; 
                  }
                  return endpoint;
              }
          }
      };
  
  })();
  </code></pre>