I am using enzyme+mocha+chai to test my react-redux project. Enzyme provides shallow to test component behavior. But I didn't find a way to test the router. I am using react-router as below:
<Router history={browserHistory}>
...
<Route path="nurse/authorization" component{NurseAuthorization}/>
...
</Route>
I want to test this route nurse/authorization
refer to NurseAuthorization
component. How to test it in reactjs project?
EDIT1
I am using react-router
as the router framework.
You can wrap your router inside a component in order to test it.
Routes.jsx
index.js
Then you have to shallow render your
Routes
component, and you are able to create an object map to check the correspondance between path and related component.Routes.test.js
I had my paths defined in another file for the dynamic router, so I am also testing that all the routes I am rendering as Routes are defined in my paths.js constants: