title: How to mock window.location.href with Jest + Vuejs?
body: <p>Currently, I am implementing unit test for my project and there is a file that contained <code>window.location.href</code>.</p>
  
  <p>I want to mock this to test and here is my sample code:</p>
  
  <pre><code>it("method A should work correctly", () =&gt; {
        const url = "http://dummy.com";
        Object.defineProperty(window.location, "href", {
          value: url,
          writable: true
        });
        const data = {
          id: "123",
          name: null
        };
        window.location.href = url;
        wrapper.vm.methodA(data);
        expect(window.location.href).toEqual(url);
      });
  </code></pre>
  
  <p>But I get this error:</p>
  
  <pre><code>TypeError: Cannot redefine property: href
          at Function.defineProperty (&lt;anonymous&gt;)
  </code></pre>
  
  <p>I had tried some solutions but not resolve it. I need some hints to help me get out of this trouble. Plz help.</p>