简体   繁体   中英

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 ).

I have tried creating an instance ( wrapper.instance() ), but this returns null. I have also tried wrapper.getElement().props , and this returns the props for the components rendered.

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() ? This is how I typically get at a component's props when using Enzyme.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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