-
Notifications
You must be signed in to change notification settings - Fork 250
click() doesn't quite work for div role="radio" #188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
click() doesn't quite work for div role="radio" #188
Comments
Hi @wKovacs64, Happy to look into this. Thanks, |
Hey @pranjaljately, I've whipped up a quick reproduction CSB. https://codesandbox.io/s/user-event-issue-188-j9brp?file=/src/__tests__/App.test.js Thanks for taking a look! |
Thanks for CSB, @wKovacs64 So from understanding, because you are changing the focus from the radio button to the input, it is not assigned instantaneously therefore, you should wrap the expect inside a
Although I can see why having the test pass when using |
I guess my confusion then lies around why Regardless, wrapping the expectation in |
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 https://codesandbox.io/s/user-event-issue-188-o0281?file=/src/__tests__/App.test.js:316-358 act(() => { // <-- required for this to work
user.click(custom)
}) Any ideas on how to do this effectively would be welcome. What I'm personally thinking is we could add a configuration option to That way, if someone imported To be clear, we wouldn't specifically include act in I have a good idea of what this will be in my head and I'll probably work on it tomorrow morning. |
This is intended for supporting `act` in React, but should be useful for other frameworks (I think it could help with triggering change detection for angular for example). Ref: testing-library/user-event#188, testing-library/user-event#255, https://github.com/testing-library/user-event/issues/277
This is intended for supporting `act` in React, but should be useful for other frameworks (I think it could help with triggering change detection for angular for example). Ref: testing-library/user-event#188, testing-library/user-event#255, https://github.com/testing-library/user-event/issues/277
Now not only will React Testing Library's `fireEvent` be wrapped in `act`, but so will DOM Testing Library's `fireEvent` (if `@testing-library/react` is imported). It works very similar to async act for the `asyncWrapper` config. Closes: testing-library/user-event#188 Closes: testing-library/user-event#255 Reference: https://github.com/testing-library/user-event/issues/277
🎉 This issue has been resolved in version 10.4.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
First, 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 callingfireEvent.click()
. I see the click logic currently looks for<input type="radio" />
and callsclickBooleanElement
, but this implementation of a radio button falls through toclickElement
.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 usinguserEvent.click
causes the focus assertion to fail.The current published version of
@testing-library/user-event
results in the radiodiv
retaining focus. I locally modified it to check for this type of element and callclickBooleanElement
instead, but that doesn't seem to be quite right either. In that version,body
ends up with focus.Thoughts?
The text was updated successfully, but these errors were encountered: