I have a Parent component that displays a Child component. The Child component first displays the unique details of the name type, and then the Parent component displays the general details of the type, and enters those details into the Child component using React.Children.map .
My problem is that Enzyme cannot detect the general attribute displayed by the Section component, so I cannot effectively check if the general attribute is being added.
Test:
const wrapper = shallow( <Parent title="Test Parent"> <div> <Child name="FirstChild" /> </div> </Parent> ) // console.log(wrapper.find(Child).node.props) <- returns only "name" in the object expect(wrapper.find(Child)).to.have.prop("commonPropOne") expect(wrapper.find(Child)).to.have.prop("commonPropTwo") expect(wrapper.find(Child)).to.have.prop("commonPropThree")
Code for the injection of general details:
const Parent = (props) => ( <div className="group" title={props.title} > { React.Children.map(props.children, child => applyCommonProps(props, child)) } </div> )
source share