onChange of input is not fired, if userEvent.type is used
See original GitHub issueHey, thank you for this library.
I have following issue and cannot figure out what I’m doing wrong.
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^13.0.13",
"@testing-library/dom": "^7.30.0",
Relevant code, which causes the issue:
// test of a parent component - the input comes from a sub-component, which uses onChange-event
const input = screen.getByPlaceholderText(/name/i);
const searchButton = screen.getByRole("button", { name: /search/i });
await userEvent.type(input, "Knight", { delay: 500 }); // onChange-event is not fired!!!
userEvent.click(searchButton);
// search-handler cannot place search, because name-input-value is empty
fireEvent works
const input = screen.getByPlaceholderText(/name/i);
const searchButton = screen.getByRole("button", { name: /search/i });
fireEvent.change(input, { target: { value: "Knight" } }); // onChange-event is fired!!!
userEvent.click(searchButton);
// search-handler can place the search
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top Results From Across the Web
onChange of input is not fired, if userEvent.type is used #676
test of a parent component - the input comes from a sub-component, which uses onChange-event const input = screen.
Read more >userEvent.type not updating value of input in test
I am testing this component, which is simply changing its state depending on new input into the input field and setting the value...
Read more >user-event v13 - Testing Library
If they are not closed explicitly, then events will be fired to close them automatically (to disable this, set the skipAutoClose option to...
Read more >Why you should test with user-event | Philipp Fritsche
Choosing the right developing tools for your project can be a daunting task. Here's why user-event should be one of them.
Read more >user-event - Bountysource
userEvent.type does not dispatch change events on input with ... Same file upload doesn't fire input event, even when clearing `input.value` $ 0....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had the same problem
This works
this doesn’t
Try to use await on userEvent.click too: