title: How to mock useHistory hook in jest?
body: <p>I am using UseHistory hook in react router v5.1.2 with typescript? When running unit test, I have got issue.</p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'history' of undefined.</p>
  </blockquote>
  
  <pre class="lang-js prettyprint-override"><code>import { mount } from 'enzyme';
  import React from 'react';
  import {Action} from 'history';
  import * as router from 'react-router';
  import { QuestionContainer } from './QuestionsContainer';
  
  describe('My questions container', () =&gt; {
      beforeEach(() =&gt; {
          const historyHistory= {
              replace: jest.fn(),
              length: 0,
              location: { 
                  pathname: '',
                  search: '',
                  state: '',
                  hash: ''
              },
              action: 'REPLACE' as Action,
              push: jest.fn(),
              go: jest.fn(),
              goBack: jest.fn(),
              goForward: jest.fn(),
              block: jest.fn(),
              listen: jest.fn(),
              createHref: jest.fn()
          };//fake object 
          jest.spyOn(router, 'useHistory').mockImplementation(() =&gt;historyHistory);// try to mock hook
      });
  
      test('should match with snapshot', () =&gt; {
          const tree = mount(&lt;QuestionContainer /&gt;);
  
          expect(tree).toMatchSnapshot();
      });
  });
  </code></pre>
  
  <p>Also i have tried use <code>jest.mock('react-router', () =&gt;({ useHistory: jest.fn() }));</code> but it still does not work.</p>