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



使用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()吗? 这就是我在使用酶时通常如何获得组件的道具。

最新更新