-
Notifications
You must be signed in to change notification settings - Fork 252
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
userEvent.selectOptions does not trigger onChange event #358
Comments
Thanks for opening this Khalid, experienced the same today and was going to put a repro together as well. If I had to guess, the following PR would have caused it: #348 |
Looks like |
@herecydev, how did you verify that clicks aren't going through when called with a single option? When I edit the test and implementation files to try multiple and non-multiple select elements (pushed up here, I can log information on click events in either case, but cannot log anything on change. Adding some screenshots of the results below: |
I think that the problem here is that React will trigger change on the bubbling phase but as I see in the code |
@marcosvega91 great debugging! If you need a workaround you could update affected tests to override the event properties. userEvent.selectOptions(select, ["second"], { bubbles: true }); Curious as to why we're not using aliased event functions e.g. |
I think that @kentcdodds can help us to understand why is not called |
It's because the browser doesn't call the change event. It calls a generic event with the type of change (like we do). |
Yes, you're correct. It just occurred to me that the event with type So all that said, I think that we should change this code so it uses A pull request to do this would be welcome :) |
Yes of course I'll open a PR for that. I'll love all these projects |
I just wanted to open an issue and saw there's already a PR for it, nice! Here's my repro: |
🎉 This issue has been resolved in version 12.0.7 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
It is happening now for select dropdowns. I am using userEvent.selectOptions to change the value. I am able to change the value but the change event is not getting triggered. I am using: @testing-library/user-event : 13.5.0 |
const dbEle=document.getElementById('schemaname') //Hi I tried the above method its working for me. The onChange event is getting triggered |
Hi @arjun-js I am facing the same issue currently. Did you find a solution yet? |
the example in OP still does not work, but in my case it's due to missing |
@testing-library/user-event
version: 12.0.0Relevant code or config
What you did:
I first noticed this behavior in a larger project, so I made a small repo to reproduce.
I made a
<select/>
element in React that fires a function received from props onChange. This behavior works as expected in the browser. When testing the behavior, I can successfully assert that a mocked version of that onChange function is called when I trigger a change event (via importingfireEvent
from RTL), but cannot assert that the same mock is called when usinguserEvent.selectOptions
.What happened:
![Screen Shot 2020-06-16 at 9 28 24 AM](https://user-images.githubusercontent.com/36432040/84794680-c6f25b00-afb3-11ea-9637-f4aa7790eb36.png)
Reproduction repository:
https://github.com/khalidwilliams/select-test-demo
Problem description:
userEvent.selectOptions
doesn't trigger a change event. onChange handlers won't fire in tests that use this method, leading to problems with testing any change-dependent behavior.Suggested solution:
I'm not sure what the best solution is, it seems like this line may not be firing as expected? Please let me know if there's something I'm missing here -- I'm happy to keep digging!
The text was updated successfully, but these errors were encountered: