I recently started to write a test, so I am not familiar with that.
When I run :
$ yarn test:coverage
I face this result:
I want to get list of Models through dispatch when my drop-down will change (formik.values.make), and also when user select models, get list of trims.
How could I write a test for these two lines:
useEffect(() => {
if (formik.values.make) {
dispatch(carModelsSuccess(formik.values.make));// <-- 59 line ***
}
if (formik.values.model) {
dispatch(carTrimsSuccess(formik.values.model));// <--- 62 line ***
}
}, [dispatch, formik.values.make, formik.values.model])
and this part :
<FormControl className={classes.formControl} disabled={!formik.values.model}>
<InputLabel id="trim">Trim</InputLabel>
<Select
data-testid="trim"
labelId="trim"
id="trim"
name="trim"
value={formik.values.trim}
onChange={formik.handleChange}
>
{carTrims?.map(({ name, value }) => (
<MenuItem value={value} key={value}>{name}</MenuItem>
))}
</Select>
</FormControl>
I work with Next.js and I want write tests with Jest and @testing-library/react. I also used material-UI for select option. I searched a lot in google on how to write tests for this code, but I couldn't find anything.
