繁体   English   中英

如何在React无状态功能组件中测试道具?

[英]How do I test props in a React stateless functional component?

使用Jest和Enzyme,我试图测试我的Logo组件是否接收正确的道具( idheightwidthactivedisableTransparency )。

我尝试创建一个实例( wrapper.instance() ),但是此方法返回null。 我还尝试了wrapper.getElement().props ,这返回了呈现组件的props。

const Logo = ({id, height, width, active, disableTransparency}) => (
    <Svg x='0px' y='0px' height={height} width={width} viewBox='0 0 1000 1000'>
        {(active) && <Gradient id={id}/>}
        {(disableTransparency) && <Underlay/>}
        <Overlay id={id} active={active}/>
    </Svg>
);

您是否尝试过wrapper.props() 这就是我通常在使用酶时获得组件道具的方式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM