Getting started
Before jumping into the testing part, make sure that you've configured
Jest or Vitest in your project
as specified in the documentation. Assume that render
, screen
and userEvent
variables
are imported from your project test-utils
file.
This guide is applicable to:
- Select
- MultiSelect
- Autocomplete
- TagsInput
- Most custom components built with Combobox
Selecting one option (Select, Autocomplete)
To select one of the options in Select or Autocomplete components, you need to:
- Click the input to open the options list
- Click the option you want to select
Note that:
- If you use an array of strings in the
data
prop, options will have the same value and label - It is recommended to set
name
attribute on all form components that you are planning to test
Selecting multiple options (MultiSelect, TagsInput)
Selecting options in MultiSelect and
TagsInput components is similar to
Select
and Autocomplete
. The main difference is that the dropdown does not close
when one of the options is selected, so you can select several options one after another
without clicking the input again.
Searching
You can verify that the component is searchable by typing search query and checking that only relevant options are visible.
Dropdown opened state
To verify that the dropdown is opened, you can check that the listbox with the same name as the input is visible.