I have a CDOB component and a DOB component that are using Mds form elements and react-hook-form's useFormContext
.
I want to write a test case for the useFormContext
methods such as watch.
Here is the code for the components:
export default function CDOB(props){
const { addr } = props;
const { watch } = useFormContext();
const code = watch(addr) ;
const getMsg =() => {
if(code == 'AL'){ return 'Invalid state'}
else {return 'Invalid entry'}
}
return( <DOB keys={age: getMsg()}/>)
}
Code for DOB component:
export default function DOB(props){
const { age } = props;
const { watch, setValue } = useFormContext();
const code = watch(addr) ;
const getMsg =() => {
if(code == 'AL'){ return 'Invalid state'}
else {return 'Invalid entry'}
}
return ( <MdsTextInput
onChange={props.onChange}
....
/>
)
}
How can I test useFormContext
’s watch method using Jest?