I'm trying to test a React functional component that I've wrapped in withRouter from react-router-dom. The component structure is as below.
import * as React from 'react';
import { Switch, Route, withRouter, RouteComponentProps } from 'react-router-dom';
export interface Props extends RouteComponentProps {
closeModalLinkPath: string;
closeModalFunction: any;
}
const RouterWrappedComponent= withRouter(({ match, history, closeModalLinkPath, closeModalFunction }: Props) => {
return (<div></div)
}
});
export default RouterWrappedComponent;
This structure works perfectly in the browser, however I am having difficulty writing unit tests. Due to the nature of the component I need an accurate match object but I can't find any way of passing this through on generation.
var routerWrappedComponent= Enzyme.mount(<MemoryRouter initialEntries={[`/studio/00000000-0000-0000-0000-000000000000/manage`]}>
<RouterWrappedComponent closeModalFunction={() => { }} closeModalLinkPath={`/studio/00000000-0000-0000-0000-000000000000`} />
</MemoryRouter>);
Despite the component's props inheriting from RouteComponentProps I can't add this to the components props and I can't find any variation of MemoryRouter that will let me pass match in through props, can anyone help?
EDIT: The withRouter wrapping came from here