title: mocking global.window in jest
body: <p>I have a function, that runs on both node and in the browser, which I want to test with jest:</p>
  
  <pre><code>const myFn = () =&gt; {
    if(typeof window !== 'object'){
       return 1;
    }
    return 2;
  }
  </code></pre>
  
  <p>How am I able to set the global window object to undefined, to test the node branch, and that 1 is returned.</p>
  
  <p>e.g.</p>
  
  <pre><code>  test('myTest', ()=&gt; {
        global.window = undefined;
        expect(myFn()).toEqual(1); // result: 2
    });
  </code></pre>
  
  <p>Ive tried the suggestions here with no success:
  <a href="https://stackoverflow.com/questions/40449434/mocking-globals-in-jest">Mocking globals in Jest</a></p>