Skip to content

KeyboardEvents not firing of handlers #122

Closed
@WhoAteDaCake

Description

@WhoAteDaCake
  • react-testing-library version: 4.0.1
  • react version: 16.4.1
  • node version: 8.9.4
  • npm (or yarn) version: (yarn 1.7.0)

Relevant code or config:

    const { container, debug } = render(<input onKeyDown={console.log} />);
    fireEvent(
      container.getElementsByTagName('input')[0],
      new KeyboardEvent('keyDown', { key: 'Enter', keyCode: 13, which: 13 })
    );

What you did:

I am trying to simulate keyboard events to validate my input component. To do that I tried to use fireEvent function with keydown and keyDown types but neither worked.

What happened:

Event handlers are not getting called

Reproduction:

https://codesandbox.io/s/n32nmp18rl

Problem description:

I can't simulate any input via keyboard

Suggested solution:

When i tried to simulate events using reacts ref and react-dom/test-utils Simulate class it seemed to work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions