[英]How do I test props in a React stateless functional component?
With Jest and Enzyme, I am trying to test that my Logo component receives the right props ( id
, height
, width
, active
, disableTransparency
). 使用Jest和Enzyme,我试图测试我的Logo组件是否接收正确的道具(
id
, height
, width
, active
, disableTransparency
)。
I have tried creating an instance ( wrapper.instance()
), but this returns null. 我尝试创建一个实例(
wrapper.instance()
),但是此方法返回null。 I have also tried wrapper.getElement().props
, and this returns the props for the components rendered. 我还尝试了
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>
);
Have you tried wrapper.props()
? 您是否尝试过
wrapper.props()
? This is how I typically get at a component's props when using Enzyme. 这就是我通常在使用酶时获得组件道具的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.