title: Mock window.close() in React-testing-library
body: <p>I have searched online but i didnt find a way to mock window.close() in react testing library or even in jest.</p>
  <pre><code>const handleClose = () =&gt; {
  window.opener.location.reload()
  window.close()
  }
  
  
  &lt;Button
    data-test-id=&quot;close&quot;
    onClick={handleClose}
  /&gt;
  </code></pre>
  <p>How do i achieve test case coverage for the onclick of button and window.close()  and window.opener.location.reload() is covered</p>
  <p>My test case is as follows</p>
  <pre><code>const wrapper = render( &lt;CloseButton /&gt;);
  const windowSpy = jest.spyOn(global, 'window', 'get');
  
  const { queryByTestId } = wrapper;
  fireEvent.click(queryByTestId('close');
  expect(windowSpy.opener.location.relaod).toHaveBeenCalled(); 
  expect(windowSpy.close).toHaveBeenCalled(); 
  
  </code></pre>
  <p>for this last line of code 'expect(windowSpy.close).toHaveBeenCalled();'
  I am getting an error that says &quot;received value must be a mock or spy function. received has value undefined&quot;</p>
  <p>For expect(windowSpy.opener.location.relaod).toHaveBeenCalled(); // it says windowSpy.opener is not defined.</p>
  <p>Please someone help !!!</p>