mardi 25 février 2020

Unit Testing with the material-ui/picker

I am utilizing the material-ui/picker in my application and would like to have full unit test coverage. I am using both the KeyboardDatePicker and KeyboardTimePicker to give the users the option to type the date and time in if they do not like using the pickers.

Where should I be declaring a 'data-testid' in order to be able to either do a fireEvent.change or a userEvent.type (or something else if there is a different recommended way of triggering this type of event)?

I have tried adding the data-testid as part of the props on the pickers themselves, as part of the inputProps, and as part of the InputAdornmentProps but then when I try running either:

fireEvent.change(getByTestId('keyboardtimepicker-testid'), { target: { value: '12:00' } })

and

await userEvent.type(getByTestId('keyboardtimepicker-testid'), '12:00')

both throw an error.

If I put the data-testid in the KeyboardButtonProps, I don't see an error but the onChange function is not getting triggered.

How should I be unit testing with components from material-ui/picker?

Aucun commentaire:

Enregistrer un commentaire