Mindaugas Jačionis Mindaugas Jačionis -3 years ago 129
React JSX Question

Enzyme doesn't see all props of react component

I have react component Button.js and it can receive few props:

type
,
onClick
and
text
. I am writing my tests to identify if component received props, but while writing tests with enzyme I can see that some props are undefined returned undefined even though I pass them.

Code of component and test is here

Answer Source

I believe the problem here is that you are passing props to the button but using the text prop as the actual text for the button.

Try testing if the text exists in the DOM(HTML). That should then pass fine.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download