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

Populate KeyboardEvent.code property #532

Closed
pahuta opened this issue Dec 23, 2020 · 2 comments
Closed

Populate KeyboardEvent.code property #532

pahuta opened this issue Dec 23, 2020 · 2 comments

Comments

@pahuta
Copy link

pahuta commented Dec 23, 2020

@testing-library/user-event version: 12.6.0
Testing Framework and version: Jest v. 26.6
DOM Environment: jsdom v. 16.4.0

Relevant code or config

// test:
userEvent.type(ui.input.get(), '{arrowdown}');


// code:
switch (event.code) { // "user-event" doesn't fill this property properly: event.code === ''
    case 'ArrowDown': {
        ...
    }
}

What you did:
I handle keyboard event by key code.

What happened:

Generated by package event doesn't contain value of event.code (actually it contains an empty string)

Reproduction repository:
none

Problem description:
In type.js file for example for event of pressing "ArrowDown" key populated properties such as key and keyCode but not a code:

function handleArrowDown({currentElement, eventOverrides}) {
  const key = 'ArrowDown'
  const keyCode = 40

  _dom.fireEvent.keyDown(currentElement(), {
    key,
    keyCode,
    which: keyCode,
    ...eventOverrides
  });

  ...
}

Suggested solution:
Adding code to corresponding places, e.g.:

function handleArrowDown({currentElement, eventOverrides}) {
  const key = 'ArrowDown'
  const keyCode = 40
  const code = 'ArrowDown';

  _dom.fireEvent.keyDown(currentElement(), {
    code,
    key,
    keyCode,
    which: keyCode,
    ...eventOverrides
  });
  ...
}

Also it should be done for all other keys.

P.S. code looks like the same as key but it is not. Value of code is independent of modifiers like shift and used language.

@ph-fritsche
Copy link
Member

See #456 and #521

@pahuta
Copy link
Author

pahuta commented Dec 23, 2020

Thanks. I closed the ticket as duplicate.

@pahuta pahuta closed this as completed Dec 23, 2020
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