title: Jest testing with URL object
body: <p>I am have a case where my code is using the URL api, created as such:</p>
  
  <p><code>const _url = new URL(window.location.href);</code></p>
  
  <p>and used like so:</p>
  
  <pre><code>if (_url.searchParams.get('locale')) {
      do something
  }
  </code></pre>
  
  <p>However in my jest tests I get an error:</p>
  
  <p><code>TypeError: Cannot read property 'get' of undefined</code></p>
  
  <p>I have tried globally mocking by doing this in my setup file:</p>
  
  <pre><code>global.URL = jest.fn(() =&gt; {
    return {
      searchParams: jest.fn(() =&gt; {
        return {
          get: jest.fn(() =&gt; {
            return '';
          }),
        };
      }),
    };
  });
  </code></pre>
  
  <p>But it doesn't seem to work. Looking at the console logged output of my <code>_url</code> object, it looks like it is missing the searchParam property all together:</p>
  
  <pre><code>URL {
    [Symbol(impl)]: URLImpl {
      _url: {
        scheme: 'http',
        username: '',
        password: '',
        host: 'localhost',
        port: null,
        path: [Array],
        query: null,
        fragment: null,
        cannotBeABaseURL: false
      },
      [Symbol(wrapper)]: [Circular]
    }
  }
  </code></pre>
  
  <p>What am I doing wrong here?</p>