Skip to content
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

userEvent.keyboard('{Escape}') not working in v14 #969

Closed
robinmetral opened this issue Jun 10, 2022 · 3 comments
Closed

userEvent.keyboard('{Escape}') not working in v14 #969

robinmetral opened this issue Jun 10, 2022 · 3 comments

Comments

@robinmetral
Copy link

robinmetral commented Jun 10, 2022

Reproduction example

https://codesandbox.io/s/v14-userevent-keyboard-escape-14jq5t

Prerequisites

  1. using @testing-library/user-event@13, create a test that does something when pressing '{Escape}' (e.g. close a dialog). v13 CodeSandbox
  2. ✅ notice all tests pass
  3. upgrade to v14. To migrate, make the tests async and await the userEvent.keyboard() call. v14 CodeSandbox
  4. 🔴 notice the test using userEvent.keyboard() fails

Expected behavior

userEvent.keyboard('{Escape}') should still work in v14

Actual behavior

It doesn't—unless I'm missing something?

User-event version

14.2.0

@robinmetral robinmetral added bug Something isn't working needs assessment This needs to be looked at by a team member labels Jun 10, 2022
@ph-fritsche ph-fritsche removed bug Something isn't working needs assessment This needs to be looked at by a team member labels Jun 10, 2022
@ph-fritsche
Copy link
Member

ph-fritsche commented Jun 10, 2022

react-modal relies on KeyboardEvent.keyCode.

KeyboardEvent.keyCode is deprecated. You should use KeyboardEvent.code instead.

We removed support for deprecated features, as we neither want to maintain features that nobody should use, nor want to encourage their usage.

See #842

You should file an issue with react-modal. Until they fix this, you can patch the event.
See #946 (comment)
See https://codesandbox.io/s/v14-userevent-keyboard-escape-forked-b9sxol?file=/src/App.test.js

@ph-fritsche ph-fritsche closed this as not planned Won't fix, can't repro, duplicate, stale Jun 10, 2022
@robinmetral
Copy link
Author

Thanks for your super fast reply, @ph-fritsche!

Sorry I missed #946—didn't realize that the issue could be caused by how react-modal handles keyboard events. I'll see if I can raise it with maintainers over there. Thanks also for the ref to the patch workaround!

@robinmetral
Copy link
Author

Note for posterity: this should be fixed in [email protected] (PR for reference: reactjs/react-modal#953)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants