Reputation: 4847
If my component is rendering the following, how can I test that Main
is being rendered using Enzyme's shallow wrapper and Jest?
<div className='App'>
{this.state.uid &&
<React.Fragment>
<Route exact path='/' render={() => <Main uid={this.state.uid} />} />
</React.Fragment>
}
</div>
Upvotes: 0
Views: 767
Reputation: 23705
Route
as any other component with find()
.render()
prop as long as we can reach <Route>
shallow()
we should get <Main ...
as a resultwrapper.state('uid')
So
expect(
wrapper
.find('Route[path="/"]')
.at(0)
.props()
.render()
).toEqual(<Main uid={wrapper.state('uid')} />)
[UPD] I think with renderProp
it should be easier to verify result:
expect(
wrapper
.find(Route)
.filter({path: '/'})
.renderProp('render')
.find(Main)
.prop('uid')
).toEqual(wrapper.state('uid'))
Upvotes: 2