I'm trying to test a component that wraps a connected component. So I have (simplified):
const InnerComponent = () => {
return (
<p>Hi!</p>
)
}
const InnerComponentWrapper = connect()(InnerComponent)
const OuterComponent = () => {
return (
<div>
<InnerComponentWrapper>
</div>
)
}
(Obviously there's more to these components, including state related stuff)
Now I'm trying to simply test that InnerComponent (or InnerComponentWrapper) is in OuterComponent. I'm using jest+enzyme. When I render OuterComponent (shallow or mount) all I can find in OuterComponent is an element with the tag of 'Connect' which doesn't have anything on it I can find that can tell me what element it's wrapping.
What I tried:
const enzymeWrapper = shallow(<OuterComponent />)
expect(enzymeWrapper.find('Connect').length).toBe(1) // pass
expect(enzymeWrapper.find('Connect(InnerComponentWrapper)').length).toBe(1) // fail
expect(enzymeWrapper.find('InnerComponentWrapper').length).toBe(1) // fail
expect(enzymeWrapper.find('InnerComponent').length).toBe(1) // fail
Thanks!
.dive()
help in your case? github.com/airbnb/enzyme/blob/master/docs/api/ShallowWrapper/… – Yangshun Tay