I have an input in a form with the following code…
<div className="Field" id="choose-date">
<div className="field-title-icon">
<label htmlFor="res-date">
Choose date<sup>*</sup>
</label>
<img className="booking-icon" src={DateImage} alt="Calendar icon"></img>
</div>
<input
type="date"
value={date}
onChange={handleDateChange}
id="res-date"
className={dateValid ? "valid-input" : "invalid-input"}
aria-required="true"
/>
</div>
I’m trying to grab it for a test using the following code…
const dateInput = screen.getByLabelText(“Choose date*”);
userEvent.type(dateInput, “2024-07-09”);
but I keep getting ” TestingLibraryElementError: Unable to find a label with the text of: Choose date*”
I’m quite new to React and I’ve checked and double-checked the code to the best of my knowledge and I’m getting nowhere. Can someone help please?
Gordon Marshall is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1