I want to write unit test for these functions.
enable () {
this.setState({
show: true
});
this.showValue();
}
showValue () {
const { model } = this.props;
model(A).onChange({ target: { value: '' } });
}
isChecked () {
if ((this.state.show)) {
if (!this.state.show) {
this.enable();
}
return true;
} else {
return false;
}
}
My test looks like this
it('isChecked', () => {
const wrapper = shallow(<Component/>);
const instance = wrapper.instance();
const mockSetStateFn = jest.fn();
instance.setState = mockSetStateFn;
instance.setState({ show: false });
instance.isChecked();
instance.enable();
expect(instance.isChecked).toHaveBeenCalledWith();
const showValue= spyOn(wrapper.instance(), 'onChange');
wrapper.find(model(A)).simulate('change', { target: { value: '' } });
expect(instance.isChecked).equals('');
});
I am getting error that onchange is not a function. I am new to unit tests. How do i write unit test for these three functions.