I have a React component that is wrapped in a higher order component with a router, as shown below:
module.exports = withRouter(ManageProfilePage);
My routes are as follows:
<Route path="/" component={AdrApp}> <IndexRoute component={Login}/> <Route component={CheckLoginStatus}> <Route path="manage-profiles/:profileId" component= {ManageProfilesPage}/> </Route> <Route path="*" component={notFoundPage}/> </Route>
I need to use once from the router lifecycle methods, so I need to use Router:
class ManageProfilePage extends React.Component { componentDidMount() { this.props.router.setRouteLeaveHook(this.props.route, () => { ... }) render(){ ... } }
I need to test this component using Jest / Enzyme, and I wrote a test case as shown below:
describe('manage profile page test suite', () => { it('snapshot test', () => { const setRouteLeaveHook =jest.fn(); let wrapper = shallow( <ManageProfilePage params={{id : 25, router: setRouteLeaveHook}}/> ); expect(wrapper).toMatchSnapshot(); }) })
The problem is that it does not provide a deep level. I am inserting a snapshot below:
exports[`manage drug term page test suites snapshot test 1`] = ` <ManageProfilePage params={ Object { "id": 25, "router": [Function], } } /> `;
Is there any other way to write my test case so that I can visualize ManageProfilePage at least at level 1? It cannot display because it is enclosed inside WithRouter? How do we test these types of components?
source share