mockRouteComponentProps.ts
1 import { RouteComponentProps } from 'react-router-dom'; 2 import { Omit } from 'react-redux'; 3 4 interface IProps { 5 match: RouteComponentProps<any>['match']; 6 location: Omit<RouteComponentProps<any>['location'], 'state'>; 7 history: { 8 length: RouteComponentProps<any>['history']['length']; 9 action: RouteComponentProps<any>['history']['action']; 10 location: RouteComponentProps<any>['history']['location']; 11 }; 12 } 13 14 export const createMockRouteComponentProps = (props: IProps): RouteComponentProps<any> => ({ 15 location: { state: {}, ...props.location }, 16 match: { 17 ...props.match 18 }, 19 history: { 20 push: () => null, 21 replace: () => null, 22 createHref: () => '', 23 block: () => () => null, 24 go: () => null, 25 goBack: () => null, 26 goForward: () => null, 27 listen: () => () => null, 28 location: { state: {}, ...props.history.location }, 29 ...props.history 30 } 31 });