title: How to properly test history.replace and history.push in React apps?
body: <p>When i try to test replace or push i either get empthy object that represents history or when i use mock it is never being called.
  Currently i get this :   Cannot spy the replace property because it is not a function; undefined given instead 
  or when i use mock it dosnt get called.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>const submitHandler = async e =&gt; {
      e.preventDefault();
      const apiUrl = 'http://localhost:8080/auth/signup'
      const signupData = {
        email,
        password,
        matchPassword,
        username
      }
      const responseData = await postData(apiUrl,signupData,'')
      if (responseData === undefined) {
        toggleValidationErrors([
          {
            param: 'server-error',
            msg: `Server isn't availdable.Please try again later!`
          }
        ]);
      } else if (responseData.validationErrors) {
        toggleValidationErrors(responseData.validationErrors);
      } else {
        history.replace(`/login`);
      }
    };
  
  import React from 'react'
  
  import {render,fireEvent, getByValue,waitForElement} from 'react-testing-library'
  import { BrowserRouter } from 'react-router-dom';
  import SignupForm from './SignupForm'
  describe('&lt;SignupForm /&gt;',() =&gt; {
      const username = "testUser";
      const email = "testEmail@email.com";
      const password = 'testpass1012'
      const matchPassword = 'testpass1012'
      const history = { replace: jest.fn() };
      const { container, getByPlaceholderText, getByValue,getByText } = render (&lt;SignupForm /&gt;,{wrapper:BrowserRouter})
      beforeEach(() =&gt; {    
  
          const submitButton = getByText('SIGN UP')
          fireEvent.click(submitButton)
      })
     
        it('should call history.replace',() =&gt; {
            
          const replaceSpy = jest.spyOn(history, 'replace');
  
            expect(replaceSpy).toBeCalled()
            replaceSpy.mockRestore()
        })
  })</code></pre>
  </div>
  </div>
  </p>