Skip to content

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

@bryan-codaio

Description

@bryan-codaio

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    accuracyImproves the accuracy of how behavior is simulated

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions