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(']') results in {key: ']', code: 'Unknown'} #1225

Open
bryan-codaio opened this issue Jun 18, 2024 · 0 comments
Open

userEvent.keyboard(']') results in {key: ']', code: 'Unknown'} #1225

bryan-codaio opened this issue Jun 18, 2024 · 0 comments
Labels
accuracy Improves the accuracy of how behavior is simulated

Comments

@bryan-codaio
Copy link

bryan-codaio commented Jun 18, 2024

Reproduction example

https://codesandbox.io/p/sandbox/festive-rhodes-5mpcfy?file=%2Fsrc%2FApp.js%3A11%2C27

Prerequisites

  1. Create a test with an onKeyDown event handler (e.g. with an <input onKeyDown={(e) => console.log(e.code)} /> element)
  2. Create a test w/ userEvent.type(inputElement, ']');

Expected behavior

The KeyboardEvent.code value ought to be 'BracketRight' same as if it were done in a browser (tested in chrome 125)

Actual behavior

The KeyboardEvent.code value is 'Unknown' per this fallback logic:

code: 'Unknown',

User-event version

14.5.1

Environment

Testing Library framework:

JS framework:

Test environment:

DOM implementation:

Additional context

I imagine the fix is a relatively simple addition to https://github.com/testing-library/user-event/blob/main/src/keyboard/keyMap.ts, but perhaps I'm missing some context

@bryan-codaio bryan-codaio added bug Something isn't working needs assessment This needs to be looked at by a team member labels Jun 18, 2024
@ph-fritsche ph-fritsche added accuracy Improves the accuracy of how behavior is simulated and removed bug Something isn't working needs assessment This needs to be looked at by a team member labels Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accuracy Improves the accuracy of how behavior is simulated
Projects
None yet
Development

No branches or pull requests

2 participants