onBeforeInput not triggering with userEvent.type
See original GitHub issue@testing-library/user-eventversion: 13.5.0
-
Testing Framework and version: jest 26.6.0
-
DOM Environment: jsdom 16.5.1
-
Node version: 15.12.0
Relevant code or config
// Does not pass
it("should trigger onBeforeInput", () => {
const mockOnBeforeInput = jest.fn();
render(<App onBeforeInput={mockOnBeforeInput} inputTestId="test-input" />);
const inputElem = screen.getByTestId("test-input");
userEvent.type(inputElem, "hello input");
// onBeforeInput is not triggered at all when calling userEvent.type
expect(mockOnBeforeInput).toBeCalledTimes(11);
});
What you did: use userEvent.type in a test to type ‘hello input’ into an input text field
What happened: onBeforeInput is not triggered when calling userEvent.type

Reproduction repository: https://codesandbox.io/s/sad-feather-8rbd7k?file=/src/App.test.js
I don’t know if this issue is solvable since I assume userEvent.type is only concerned with triggering key events (whereas onBeforeInput and onInput are specific to input elements), but I’m just raising this in the hopes that there is a possible fix 🙏
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
React Testing Library: UserEvent.type not working
Problem: UserEvent.type is not working. I have a simple test where I get the textbox, which works, but when trying to type in...
Read more >user-event - Bountysource
userEvent.type does not dispatch change events on input with @testing-library/dom $ 0 ... onBeforeInput is not triggered at all when calling userEvent.type ......
Read more >Utility APIs - Testing Library
Type into an input element. You should use keyboard() if you want to just simulate pressing buttons on the keyboard. You can use...
Read more >@testing-library/user-event - npm
Simulates the keyboard events described by text . This is similar to userEvent.type() but without any clicking or changing the selection range.
Read more >Why you should test with user-event | Philipp Fritsche
It's been a while since I stumbled over Testing Library and their user-event package. Something not working yet at the time bugged me...
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 Free
Top 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

The
configurefunction is invoked and reexported from@testing-library/domby@testing-library/react. If it just were imported by your setup, that would make no difference to importing anything else from@testing-library/react. However, if it is invoked, the configuration by@testing-library/reactalready took place and you might override theasyncWrapperand/oreventWrapper.Hey @ph-fritsche, thanks for the feedback, I’ve had a quick look and noticed that we import this in quite a few places so I’ll update and try again. Thanks for your help, greatly appreciated 🙇