I'm trying to test a component with the MemoryRouter
as indicated in the React-router docs with initial entries set so I can have params inside the wrapped component.
Component example :
render () {
console.log(this.props.match.params.item)
}
In the App (works fine) :
<Router>
<Switch>
<Route exact path='/' render={() => (
<Redirect to={`/${guessLocale()}`} />
)} />
<Route exact path='/:lang' component={Home} />
<Route exact path='/:lang/:itemName' component={Vidactic} />
</Switch>
</Router>
In the test (mount from Enzyme, match is undefined) :
mount(<MemoryRouter initialEntries={['/fr/pamp']}>
<Vidactic />
</MemoryRouter>)
So I used this workaround but why initialEntries would not work by itself ?
mount(<MemoryRouter initialEntries={['/fr/pamp']}>
<Vidactic match={{ params: { item: 'pamp' } }} />
</MemoryRouter>)