title: How to mock $window.location.href in Angular using Jasmine
body: <p>I have a Factory in Angular which contains a function that expects a string as an argument, checks if that string is set as an Get Parameter in the URL and returns the Value of that Parameter if set. </p>
  
  <p>A really simplified version of that function in some sort of pseudo code looks like this</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function getParameterValueByName(parameterName) {
    
    url = $window.location.href;
    
    if (parameterName is in url) {
      
      return THE VALUE FROM parameterName;
      
    }
    
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>In Jasmine I need to test what this functions returns for different URL's. I have to run multiple Tests with different values in <code>$window.location.href</code>. But how to mock <code>$window.location.href</code>?</p>
  
  <p>+++++</p>
  
  <p>I finally found a way to do it. I just had to add this snippet. And everytime I want to change this URL I just create a new describe Block.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>beforeEach(module('myApp', function ($provide) {
        $provide.value('$window', {location: {href: 'https://www.example.com?foo=bar&amp;foo2=bar2'}});
  }));</code></pre>
  </div>
  </div>
  </p>