You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DOM Environment:
"@testing-library/jest-dom": "^6.6.2",
"jest-environment-jsdom": "^29.7.0",
Problem description:
Jest does not treat a div with role="listbox" as focusable.
Relevant code or config:
This code should fail its test if the "listbox" in the dropdown component does not have tabIndex={-1}, but it does not error because dom-testing-library doesn't treat a div with role="listbox" as focusable as far as I can tell.
it.only('should not allow focus of dropdown-options container itself',async()=>{render(<><button>I start focused</button><Dropdownoptions={options}/><inputtype='text'/></>)constelementThatStartsFocused=screen.getByRole('button')constdropdownOptionsContainerDivItself=screen.getByTestId('dropdown-options')constallTextBoxes=screen.getAllByRole('textbox')constexternalOtherInput=allTextBoxes[allTextBoxes.length-1]constallDropDownOptions=screen.getAllByTestId('dropdown-option')// Focus button above ddawaituserEvent.click(elementThatStartsFocused)expect(elementThatStartsFocused).toHaveFocus()console.log('clickedButton',document.activeElement?.outerHTML)// Focus dd optionawaituserEvent.tab()// Wait for the dropdown to become visible and options to be renderedawaitwaitFor(()=>{expect(screen.getAllByTestId('dropdown-option')).toHaveLength(options.length)})awaitwaitFor(()=>{expect(allDropDownOptions[0]).toHaveFocus()})console.log('tabbedintofirstoption',document.activeElement?.outerHTML)expect(dropdownOptionsContainerDivItself).not.toHaveFocus()awaituserEvent.click(externalOtherInput)console.log('clikedInput',document.activeElement?.outerHTML)awaituserEvent.tab({shift: true})console.log('shiftTabbed into dd 1st option',document.activeElement?.outerHTML)awaitwaitFor(()=>{expect(allDropDownOptions[0]).toHaveFocus()})console.log({previousTOFocus: document.activeElement?.outerHTML})awaituserEvent.tab({shift: true})console.log({final: document.activeElement?.outerHTML})expect(dropdownOptionsContainerDivItself).not.toHaveFocus()expect(elementThatStartsFocused).toHaveFocus()})
Hi @Stan-Stani, thanks for opening this.
We're not the one's deciding which element is focusable or not. Are you able to focus on the element programmatically without testing library (using JSDOM) and this doesn't work when you're adding DTL?
@testing-library/dom
version:jest@npm:29.7.0
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/react": "^15.0.7",
"jest-environment-jsdom": "^29.7.0",
Problem description:
Jest does not treat a div with role="listbox" as focusable.
Relevant code or config:
This code should fail its test if the "listbox" in the dropdown component does not have tabIndex={-1}, but it does not error because dom-testing-library doesn't treat a div with role="listbox" as focusable as far as I can tell.
Reproduction:
I will work on this part soon!
Suggested solution:
Have dom-testing-library treat divs with role="listbox" as focusable.
The text was updated successfully, but these errors were encountered: