I am trying to test react-router with react testing library / jest, how would I test the following with correct coverage? using react-router-dom 5.2.0
Routing component
<BrowserRouter>
<Header links={Items} />
<div className="App">
<Switch>
<Route exact path="/">
<Redirect to="/home" />
</Route>
<Route exact path={["/home", "/"]} component={home} />
<Route path="/brochure/:id" render={(props: RouteComponentProps<any>) => <Brochure {...props} />} />
<Route exact path="/detail" render={() => <Details />} />
<Route component={NotFound} />
</Switch>
</div>
</BrowserRouter>
Test
I have done the following:
it('Should render routing', () => {
const history = createMemoryHistory()
render(
<Router history={history}>
<Routing />
</Router>,
)
expect(screen.getByText(/Home/i)).toBeInTheDocument()
expect(screen.getByText(/Details/i)).toBeInTheDocument()
});
This passes, but it’s not really testing it properly? Any idea’s