title: AngularJS + Jasmine: Unexpected http calls
body: <p>I started writing tests for an existing application and encountered two problems.</p>
  
  <p>Here is service method I'm trying to cover:</p>
  
  <pre><code>    function getClinic(id) {
          return $http
              .get("api/clinic/" + id)
              .then(function (resp) {
                  return resp.data;
              })
      }
  </code></pre>
  
  <p>With </p>
  
  <pre><code> it('should test getClinic method http call', function() {
    $httpBackend
      .expectGET("api/clinic/" + clinicId)
      .respond(200, $q.when(successResponse));
  
    clinicManager.getClinic(clinicId)
      .then(function(res) {
        httpOutput = res;
      });
  
    $httpBackend.flush();
  
    expect(clinicManager.getClinic).toHaveBeenCalledWith(clinicId);
    expect(httpOutput).toEqual(successResponse);
  });
  </code></pre>
  
  <p>But I got the following error</p>
  
  <pre><code>Error: Unexpected request: GET /api/users/current
  </code></pre>
  
  <p>Indeed, I do have the following route called on app load</p>
  
  <pre><code>angular
      .module('module', [...])
      .config(...) 
      .run(function (userManager) {
          userManager.setCurrentUser();
          // I put this logic here to fetch currently logged user from back-end on every app load
      })
  </code></pre>
  
  <p>After removing <code>userManager.setCurrentUser();</code> I got another error</p>
  
  <pre><code>Error: Unexpected request: GET /dashboard
  </code></pre>
  
  <p>So the <code>/dashboard</code> is initial page which is specified in $routeProvider</p>
  
  <pre><code> function Routes($routeProvider) {
      $routeProvider
        .when('/', {
          templateUrl: '/dashboard',
          controller: 'dashboard.ctrl',
        })
        .when('/dashboard', {
          templateUrl: '/dashboard',
          controller: 'dashboard.ctrl',
        })
        //... other routes
       .otherwise({
         redirectTo: '/dashboard',
       });
  </code></pre>
  
  <p>So my question is how can I avoid getting those two errors without putting http expectations into every single service test kit?</p>