title: Jest Testing Electron/React Component using window.require
body: <p>I'm currently creating an Electron application that uses React to create the interface. In order to get access the fs, I have been using:</p>
  
  <pre><code>const fs = window.require('fs');
  </code></pre>
  
  <p>Which works fine when in an Electron window. </p>
  
  <p>The issue is that when I write jest tests for any components that use the window.require('fs'), I get the following error when running the test.  </p>
  
  <pre><code>TypeError: window.require is not a function
  </code></pre>
  
  <p>I have looked through the documentation for Jest and it seems the solution is to generate a mock of window using a manual mock (see "Mocking methods which are not implemented in JSDOM" at <a href="https://jestjs.io/docs/en/manual-mocks" rel="noreferrer">https://jestjs.io/docs/en/manual-mocks</a>). However, when I tried to mock window.require by adding at the top of my test file</p>
  
  <pre><code>window.require = jest.fn(); 
  </code></pre>
  
  <p>I still get the same TypeError.</p>
  
  <p>I'm very new to create Jest mocks so any help with this would be much appreciated.</p>
  
  <p>My current test file (Component.test.js) looks like </p>
  
  <pre><code>window.require = jest.fn();
  
  import React from 'react';
  import renderer from 'react-test-renderer';
  import Component from '../index';
  
  describe('Testing', () =&gt; {
      it('Component renders correctly', () =&gt; {
          const component = renderer.create(&lt;Component /&gt;);
          let tree = component.toJSON();
          expect(tree).toMatchSnapshot();
      });
  });
  </code></pre>