-
Notifications
You must be signed in to change notification settings - Fork 251
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
onBeforeInput not triggering with userEvent.type #858
Comments
Support for |
Thanks very much! |
It seems this issue can be reproduced again, try to run this:
my version is 14.1.0, could someone have a look? |
@M162 Thanks for reporting this. test('React triggers `onBeforeInput`', async () => {
const onBeforeInput = jest.fn();
const beforeInputListener = jest.fn()
render(<input onBeforeInput={onBeforeInput}/>);
screen.getByRole('textbox').addEventListener('beforeinput', beforeInputListener)
await userEvent.type(screen.getByRole('textbox'), 'abcdef');
expect(beforeInputListener).toHaveBeenCalledTimes(6);
expect(onBeforeInput).toHaveBeenCalledTimes(6);
}); |
It looks like this isn't really an issue with The following comment suggests that the This leads to As React determines the The workaround with the least harm is probably to make React think it is running in a Webkit-like environment and patch If you want to use |
Hi @ph-fritsche, many thanks for your help. I tried your workaround and it does work in CodeSandbox. However, the tricky thing is it does not work when I run it locally. I didn't change anything and the version of testing-library/jest-dom, testing-library/react, testing-library/user-event, react, react-dom are also all the same. Do you have any idea why it doesn't work? Thank you again. |
I finally find the reason why it doesn't work in my local. It is because I import the 'configure' function from @testing-library/react. It will change something of the environment by just import this function. I will open an issue in react testing library repo. Again thanks for your help, now it works in my local. @ph-fritsche |
Hey @M162, what was the reason that |
Hi @jwarykowski, I import 'configure' in my 'setupFilesAfterEnv' of jest configurations. If I remove the import, then everything works fine. To be honest, I don't know what happened exactly, so I guess it changed something in environment when I import it. I don't even know if it is a bug or not, so I don't raise it in react testing library repo finally. |
Hey @M162, thanks for the quick feedback. Sorry @ph-fritsche, do you have any idea why this would be the case? |
The |
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 🙇 |
@testing-library/user-event
version: 13.5.0Testing Framework and version: jest 26.6.0
DOM Environment: jsdom 16.5.1
Node version: 15.12.0
Relevant code or config
What you did: use
userEvent.type
in a test to type 'hello input' into an input text fieldWhat happened:
onBeforeInput
is not triggered when callinguserEvent.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 (whereasonBeforeInput
andonInput
are specific to input elements), but I'm just raising this in the hopes that there is a possible fix 🙏The text was updated successfully, but these errors were encountered: