I am using react-final-form to validate the input field as below:
buildInputComponent() {
return (
<InputField
id="input-field"
label="description"
isInvalid={meta.touched && !meta.valid}
error={meta.error}
value=input.value
required
onChange={(event) => {
input.onChange(event.target.value);
}}
/>);
}
i have tested it as follows:
it('sets the frequency state to the value in the frequency select', ()
=> {
const inputValue = '30';
testInput.find('input-field').find('input').hostNodes()
.simulate('change', { target: { value: inputValue } });
testInput.update();
expect(testInput.find('ReactFinalForm').instance().state.schedule.frequency).toEqual(frequency);
});'
This covers the test for meta.touched, but the coverage report shows it does not cover the test for !meta.valid I have no idea how to cover the test for !meta.valid I tried having empty field as below:
testInput.find('input-field').find('input').hostNodes()
.simulate('change', { target: { value: frequency } });
But this did not cover it, Please help
I suspect that your touched
is always false because you are not focusing and blurring the field, ergo the latter half of the &&
is never evaluated.