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

问题描述 投票:0回答:1

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

我尝试过创建一个实例(wrapper.instance()),但这会返回null。我也尝试过wrapper.getElement().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>
);
javascript reactjs react-native ecmascript-6 jestjs
1个回答
0
投票

你试过wrapper.props()吗?这就是我在使用Enzyme时通常会获得组件的道具。

© www.soinside.com 2019 - 2024. All rights reserved.