| 245 | * @param optionText - The text of the option to select. |
| 246 | */ |
| 247 | export async function selectReactSelectOption( |
| 248 | container: HTMLElement, |
| 249 | optionText: string, |
| 250 | ) { |
| 251 | const input = container.querySelector("input"); |
| 252 | assert(input !== null, "Could not find react-select input"); |
| 253 | await userEvent.click(input); |
| 254 | const optionEls = Array.from(container.querySelectorAll('[role="option"]')); |
| 255 | const option = optionEls.find((el) => el.textContent === optionText); |
| 256 | assert( |
| 257 | option !== undefined, |
| 258 | `Could not find react-select option '${optionText}'. Found: ${buildStringifiedOptions(optionEls)}`, |
| 259 | ); |
| 260 | await userEvent.click(option); |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Determine whether there are invalid form fields in the document. |