Reputation: 237
I have a component which looks like this
const Menu_ = props =>
<div
onClick={() => props.onClick("users")}
/>
and a Jest setup, like:
const tree = renderer
.create(<Menu_ page={""} onClick={page => null} />)
.toJSON();
I feel like I should be able to call
tree.props.onClick();
but... the renderer function from the 'react-test-renderer' package doesn't show me the props required props.
Is there a nice way to test; get access to the onClick prop; without touching my current code too much?
Upvotes: 0
Views: 494
Reputation: 34
Note that what you're doing is creating component
.create(<Menu_ page={""} onClick={page => null} />)
but then you turn this structure to JSON format:
.toJSON();
This structure can only hold pure data, not functions. You may want to take a look at enzyme
and it render methods.
Upvotes: 0