title: Mock objects required by actual function from test spec file
body: <p>I have a method/function in actual JS file(main.js) that goes like this:</p>
  
  <pre><code>function returnPath() {
      return `path=${encodeURIComponent(window.location.href.replace(window.location.origin, ''))}`;
  }
  </code></pre>
  
  <p>Now, in my jasmine spec file (mainSpec.js), I have the below code:</p>
  
  <pre><code> describe('Test returnPath function', () =&gt; {
  
          it('test the path string returned', () =&gt; {
  
            const window = {
              location: {
                  href: "https://www.example.com/hello/world",
                  origin: "https://www.example.com/"
              }
            };
            const pathStr = returnPath();
  
            // assert
            expect(pathStr).toBe('path=hello%2Fworld');
          });
  
        });
  </code></pre>
  
  <p>But, when I run my test, it fails as the window.location.href does not point to the custom object initialized in the 'it' block. </p>
  
  <p>How to inject/provide objects needed by the actual function from the spec file?</p>