Reputation: 889
What I am trying to test in MyComponent
is the value of checked
props of the Switch
component which is a props of FormControlLabel
component:
class MyComponent extends Component {
(...)
render() {
return (
<FormControlLabel
name={`formControl`}
control={
<Switch
name={`switch`}
data
checked={this.state.isChecked}
onClick={this.handleChange}
value={checked}
/>
}
/>
);
}
}
I can access the FormControlLabel
component like this:
const wrapper = shallow(<MyComponent />);
wrapper.find('[name="formControl"]');
I tried to access the Switch
component like this but it's not working:
wrapper.find('[name="switch"]');
How can I access the checked
props of Switch
component ?
Upvotes: 10
Views: 5342
Reputation: 4752
const controlComponent = shallow(wrapper.find(FormControlLabel).props().control);
expect(controlComponent.props().checked).toBeTruthy();
Upvotes: 1
Reputation: 889
Well, I just found a solution:
expect(wrapper.find('[name="formControl"]').prop('control').props.checked).toEqual(true);
Upvotes: 12