Skip to content

Add support for arrowdown and arrowup events #503

@corymharper

Description

@corymharper
  • Testing-library/user-event` version: 12.2.2
  • Testing Framework and version: jest/26.0.15
  • DOM Environment: react-dom/17.0.0

What you did:

I have a module I'm migrating from Enzyme over to testing-library, the module is a React hook that for the most part manages keyboard controls to follow accessibility guidelines for dropdown menus. Part of our tests simulate arrowdown and arrowup events while focused on list items to ensure the correct resulting focused element is obtained. We ran into this issue while trying to replicate that behavior using userEvent.

What happened:

userEvent.type only supports ArrowLeft and ArrowRight keys.

Problem description:

While trying to implement tests to replace Enzyme with testing-library we were attempting to use userEvent instead of fireEvent where ever possible, as suggested by the documentation. However, we are currently unable to replicate tests that used ArrowDown and ArrowUp as that's just not one of the special characters supported by userEvent.type.

Suggested solution:

Add ArrowDown and ArrowUp as supported special keys for userEvent.type. Also, while reading over the documentation and through some issues, the documentation for userEvent.type seems off the mark for the variety of purposes it is used for now:

Writes text inside an or a <textarea>.

This should probably be modified to indicate that it's used with a variety of types of elements now, or a new method could be added to userEvent meant for these situations were you aren't necessarily "typing".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions