-
Notifications
You must be signed in to change notification settings - Fork 1.1k
onChange event not firing #637
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
Comments
What is the expected behavior you're looking for? It seems like you have an issue with |
Hi, Expected behaviour: Issue: |
I believe to get what you want you'd need to do: fireEvent.change(input, { target: { value: `${input.value}a` } }) Alternatively, I believe this should work (using userEvent.type(input, 'a') |
Thanks! So I'm not sure the first option would be useful for this test, as (if I understand correctly), I would essentially be triggering a user input which would be ${input.value}a (= writea), and then checking that this is indeed what I would have received. This efficiently checks that the initial input.value is "write", but doesn't check that the function handleOnChange does its job. And I've already checked the first part via another test (that I didn't write in my initial post to simplify). The second option you're suggesting seems that it would indeed check what I want to check, however I do not seem to be able to find userEvent, which comes back as undefined. @testing-library/user-event was already installed as part of create-react-app and I've tried to re-add it with npm just in case, but this doesn't change anything. Checking the docs I also tried to add await in front of userEvent in case that would make a difference, but I then get an error saying I am not in an async function. -- -- |
Make sure you do: import userEvent from '@testing-library/user-event' |
Ah of course my bad, I had placed userEvent in curly brackets. Sorry for that! |
Well it works in my apps when I do it 🤷♂️ Without an actual example (like on in https://kcd.im/rtl-help) there's not much we can do for you. So feel free to make one there if you'd like more help. Also, because this is most likely not a bug in Testing Library, I'm going to close this and refer you to https://spectrum.chat/testing-library if you have further questions. Thanks :) |
I am also facing the same issue. The value that I am getting is the updated one but the onChange event is not getting triggered. |
Would be great if you could make a reproducible case e.g. with Codesandbox.com |
This is pretty strange. The test is passing in codesandbox but the same code is not passing on my codebase. Update: |
@testing-library/react
version: ^9.3.2react
version: ^16.13.1node
version: v8.12.0npm
(oryarn
) version: 6.4.1Relevant code or config:
Input.js
Input.test.js
OR if using fireEvent:
Input.test.js
What you did:
I am using the latest version of create-react-app.
I created an input which value changes when a user inputs something new.
"write" + a inputed becomes "writea". This works.
What happened / Problem description:
When testing it, it doesn't seem to work.
If I use fireEvent, I receive "a"
If I use Simulate, I receive "write"
and get an error: "Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function. in Input (at Input.test.js:6)"
Suggested solution:
I had a look here: #359 but couldn't identify what might be the problem.
It might just be me badly implementing something - if so, my apologies!
The text was updated successfully, but these errors were encountered: