question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onChange of input is not fired, if userEvent.type is used

See original GitHub issue

Hey, 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
yuritoledocommented, Feb 3, 2022

I had the same problem

This works

 fireEvent.change(screen.getByTestId('asdasd'), {
      target: { value: 'hahahahahahahaha' },
    });

this doesn’t

    userEvent.type(screen.getByTestId('asdasd'), 'hahahahahahahaha');
5reactions
lionfflcommented, Jun 3, 2022

Try to use await on userEvent.click too:

await userEvent.type(input, "Knight");
await userEvent.click(searchButton);
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found