import React , { Component , ComponentType } from 'react' ; import { MemoryRouter , Route , withRouter } from 'react-router-dom' ; import * as H from 'history' ; export const WithMemoryRouter = ( initialEntries = [ '/' ] , initialIndex = 0 ) => ( WrappedComponent ) => ( props ) => ( < MemoryRouter initialEntries = { initialEntries } initialIndex = { initialIndex } > < WrappedComponent { ... props } / > < /MemoryRouter>); export const WithRoute = ( componentRoutePath = '/' , onRouter = ( router ) => { } ) => ( WrappedComponent ) => { const CatchRouter = withRouter ( class extends Component < any > { componentDidMount ( ) { const { match , location , history } = this . props ; const router = { route : { match , location } , history } ; onRouter ( router ) ; } render ( ) { return < WrappedComponent { ... this . props } / > ; } } ) ; return ( props ) => ( < Route path = { componentRoutePath } render = { ( routerProps ) => < CatchRouter { ... routerProps } { ... props } />}/ > ) ; } ; interface Router { history : Partial < H . History > ; route : { location : H . Location ; } ; } export const reactRouterMock = { history : { push : ( ) => { } , createHref : ( location ) => location . pathname ! , location : { pathname : '' , search : '' , state : '' , hash : '' , } , } , route : { location : { pathname : '' , search : '' , state : '' , hash : '' , } , } , } ;