title: How to avoid location.reload() in angular tests via jasmine, and test it
body: <p>In one of my controllers I have a <code>location.reload()</code></p>
  
  <p>(For those who wants to know why, My login page does not load the entire app before the user logs in to reduce threshold on the server)</p>
  
  <p>When I test the controller (using jasmine html for the ui), it actually reloads the test in an infinite loop.</p>
  
  <p>My questions is this: </p>
  
  <p><strong>How do I avoid the location.reload() from loading the test itself, and how do I even check whether it has been called? can I mock it somehow?</strong></p>
  
  <p>Here's the code for the controller:</p>
  
  <pre><code>(function() {
      'use strict';
  
      angular
      .module('app.ctrls')
      .controller('LoginController', LoginController);
  
      LoginController.$inject = [ '$scope', 'AuthService' ];
  
      function LoginController($scope, AuthService)
      {
          console.log('LoginController');
          $scope.credantials = {
                  email:      '',
                  password:   '',
                  remember:   false
          }
          $scope.login = function(credantials)
          {
              AuthService.login(credantials.email, credantials.password, credantials.remember || false).success(function(response) {
                  console.log(response);
                  if (response.email !== null)
                  {
                      $scope.logged = true;
                      console.log('login successful');
                      location.reload();
                  }
                  else
                  {
                      $scope.logged = false;
                      $scope.error = true;
                  }
              }).error(function() {
                  console.log('failed to login');
              });
          };
      }
  })();
  </code></pre>
  
  <p>Here's the spec:</p>
  
  <pre><code>describe("successfully logged in", function() {
      it("should reload the page", function() {
          this.scope.credantials = { email: 'test@mail.com', password: '123', remember: false };
          this.$httpBackend.expectPOST('/auth/login', this.scope.credantials).respond({first_name: "Bakayaru", email: "test@mail.com"});
          this.$httpBackend.whenGET('/tpls/home.html').respond(200);
          this.scope.login(this.scope.credantials);
          this.$httpBackend.flush();
          expect(this.scope).toBeDefined();
          expect(this.scope.logged).toBeTruthy();
          /* -------&gt; TEST that location.reload() has been called HERE &lt;--------- */
      });
  });
  </code></pre>