userEvent.keyboard(']')
results in {key: ']', code: 'Unknown'}
#1225
Labels
accuracy
Improves the accuracy of how behavior is simulated
Reproduction example
https://codesandbox.io/p/sandbox/festive-rhodes-5mpcfy?file=%2Fsrc%2FApp.js%3A11%2C27
Prerequisites
onKeyDown
event handler (e.g. with an<input onKeyDown={(e) => console.log(e.code)} />
element)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:user-event/src/keyboard/parseKeyDef.ts
Line 41 in d036279
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
The text was updated successfully, but these errors were encountered: