[英]How to properly use React.StatelessFunctionalComponent<Props> on a stateless functional component?
[英]How do I test props in a React stateless functional component?
使用Jest和Enzyme,我试图测试我的Logo组件是否接收正确的道具( id
, height
, width
, active
, disableTransparency
)。
我尝试创建一个实例( 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.