admin管理员组文章数量:1327661
I have a Parent
ponent that renders a Child
ponent. The Child
ponent first renders unique props like 'name' and then the Parent ponent renders mon props such as 'type' and injects those props into the Child
ponent using React.Children.map
.
My problem is that Enzyme is not able to detect the mon props rendered by the Section
ponent so I cannot effectively test whether or not the mon props are being added.
The 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("monPropOne")
expect(wrapper.find(Child)).to.have.prop("monPropTwo")
expect(wrapper.find(Child)).to.have.prop("monPropThree")
I have a Parent
ponent that renders a Child
ponent. The Child
ponent first renders unique props like 'name' and then the Parent ponent renders mon props such as 'type' and injects those props into the Child
ponent using React.Children.map
.
My problem is that Enzyme is not able to detect the mon props rendered by the Section
ponent so I cannot effectively test whether or not the mon props are being added.
The 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("monPropOne")
expect(wrapper.find(Child)).to.have.prop("monPropTwo")
expect(wrapper.find(Child)).to.have.prop("monPropThree")
The code for injecting mon props:
const Parent = (props) => (
<div
className="group"
title={props.title}
>
{ React.Children.map(props.children, child => applyCommonProps(props, child)) }
</div>
)
Share
Improve this question
edited May 11, 2019 at 13:50
Zoe - Save the data dump
28.3k22 gold badges128 silver badges160 bronze badges
asked May 20, 2016 at 17:03
cmwallcmwall
4672 gold badges6 silver badges15 bronze badges
1 Answer
Reset to default 5You will have to use enzyme's mount.
mount
gives you full DOM rendering when you need wait for ponents to render children rather than only rendering a single node like shallow
.
本文标签: javascriptHow to wait for complete render of React component in Mocha using EnzymeStack Overflow
版权声明:本文标题:javascript - How to wait for complete render of React component in Mocha using Enzyme? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742229786a2437008.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论