menu

Testing Library

Simple and complete DOM testing utilities that encourage good testing practices.

Channels
Chat
view-forward
# All channels
view-forward
# General
view-forward
# General Help
view-forward
# Angular Help
view-forward
# Cypress Help
view-forward
# DOM Help
view-forward
# React Help
view-forward
# TestCafe Help
view-forward
# Vue Help
view-forward
Team

React: Test select options list (ie, test ordering)

January 20, 2020 at 11:44pm

React: Test select options list (ie, test ordering)

January 20, 2020 at 11:44pm
What are patterns that are available in react-testing-library to test the options list of a select element itself? When I search for solutions, I often see people running into (solvable) challenges with interacting with a select element. However, there is very little about testing the select list itself.
Right now, I'm considering breaking out logic that sorts the select options list into its own little function and writing a test just for that function. This helps remove React and and the DOM from the equation. However, I want to see first if there are any existing patterns for this kind of problem.
Thank you.

January 21, 2020 at 2:02am
try this
const select = getByRole("listbox"),
const options = within(select).getAllByRole("option")
Edited
  • reply
  • like