click() doesn't quite work for div role="radio"
See original GitHub issueFirst, thanks for this library - great abstraction.
I just tried to use the userEvent.click()
function on a radio button that is implemented as <div role="radio" />
(e.g. @palmerhq/radio-group
) and it didn’t quite yield the same expected behavior as directly calling fireEvent.click()
. I see the click logic currently looks for <input type="radio" />
and calls clickBooleanElement
, but this implementation of a radio button falls through to clickElement
.
In the actual application, clicking said radio button moves the focus to an input field that becomes enabled when this radio button is selected. If I use fireEvent.click
to select the radio button, asserting focus to be on the text input afterwards is successful. But using userEvent.click
causes the focus assertion to fail.
The current published version of @testing-library/user-event
results in the radio div
retaining focus. I locally modified it to check for this type of element and call clickBooleanElement
instead, but that doesn’t seem to be quite right either. In that version, body
ends up with focus.
Thoughts?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
🎉 This issue has been resolved in version 10.4.1 🎉
The release is available on:
npm package (@latest dist-tag)
Your semantic-release bot 📦🚀
I believe this actually is evidence of an issue we should address in user-event. We’ve discussed this in the past and I assumed that we didn’t need to worry about wrapping
userEvent
inact
, but based on this example, I think it’s clear we need to figure out a way to automatically wrapuserEvent
inact
.https://codesandbox.io/s/user-event-issue-188-o0281?file=/src/__tests__/App.test.js:316-358
Any ideas on how to do this effectively would be welcome.
What I’m personally thinking is we could add a configuration option to
@testing-library/dom
for wrappingfireEvent
in act just like we do for the async act stuff. https://github.com/testing-library/react-testing-library/blob/0afcbea3c3d1ddce218a36d963d39fa83f9a7cf6/src/pure.js#L12-L20That way, if someone imported
@testing-library/react
, they would automatically configure@testing-library/dom
to wrapfireEvent
in act rather than having to do this fancy stuff.To be clear, we wouldn’t specifically include act in
@testing-library/dom
, but would instead enable people to do whatever they link whenever an event is fired.I have a good idea of what this will be in my head and I’ll probably work on it tomorrow morning.