Stubbing window.location.href with Sinon : <p>I am trying to test some client-side code and for that I need to stub the value of <code>window.location.href</code> property using Mocha/Sinon.</p>

<p>What I have tried so far (<a href="https://gist.github.com/jouni-kantola/8761980" rel="noreferrer">using this example</a>):</p>

<pre><code>describe('Logger', () =&gt; {
    it('should compose a Log', () =&gt; {
        var stub = sinon.stub(window.location, 'href', 'http://www.foo.com');
    });
});
</code></pre>

<p>The runner displays the following error:</p>

<blockquote>
  <p>TypeError: Custom stub should be a function or a property descriptor</p>
</blockquote>

<p>Changing the test code to: </p>

<pre><code>describe('Logger', () =&gt; {
    it('should compose a Log', () =&gt; {
        var stub = sinon.stub(window.location, 'href', {
            value: 'foo'
        });
    });
});
</code></pre>

<p>Which yields this error:</p>

<blockquote>
  <p>TypeError: Attempted to wrap string property href as function</p>
</blockquote>

<p>Passing a function as third argument to <code>sinon.stub</code> doesn't work either.</p>

<p>Is there a way to provide a fake <code>window.location.href</code> string, also avoiding redirection (since I'm testing in the browser)?</p>
