title: Is it possible to mock the window.location object for a qUnit test?
body: <p>Let's say I have a utility function that, for simplicity's sake (the real thing is complicated and irrelevant), returns the current window's querystring.</p>
  
  <pre><code>var someUtilityFunction = () {
      return window.location.search.substring(1);
  };
  </code></pre>
  
  <p>Now I want to unit test this function in qUnit (not sure if the testing harness is relevant or not):</p>
  
  <pre><code>test('#1 someUtilityFunction works', function () {
      // setup
      var oldQS = window.location.search;
      window.location.search = '?key1=value1&amp;key2=value2&amp;key3=value3';
  
      var expectedOutput = 'key1=value1&amp;key2=value2&amp;key3=value3';
  
      // test
      equals(someUtilityFunction(),
          expectedOutput,
          'someUtilityFunction works as expected.');
  
      // teardown
      window.location.search = oldQS;
  });
  </code></pre>
  
  <p>The problem here is that setting the <code>window.location.search</code> to a different querystring is causing the page to reload, essentially entering an infinite request loop. Is there any way to mock out the window.location object <strong>without</strong> making any changes to the <code>someUtilityFunction</code> function?</p>