Skip to content

fireEvent.keyPress not fire in test #269

Closed
@zhaozhiming

Description

@zhaozhiming
  • react-testing-library version: 5.4.4
  • react version: 16.5.2
  • node version: 10.0.0
  • npm (or yarn) version: yarn 1.9.2

Relevant code or config:

  test("input key press correctly", () => { // failed
    const doSomething = jest.fn();
    const doOtherThing = jest.fn();
    const { container } = render(
      <App doSomething={doSomething} doOtherThing={doOtherThing} />
    );
    const input = getByTestId(container, "input");
    fireEvent.keyPress(input, { key: "Enter", code: 13 });
    expect(doSomething.mock.calls.length).toBe(1);
  });

What you did:

run test

What happened:

test failed

Reproduction:

https://codesandbox.io/s/jrv9v845v

Problem description:

When use fireEvent.keyPress, the input keyPress event not fired.
I found the doc about this part of the content, but I don't know what different between the keyPress event and change event.
image

Suggested solution:

I have no idea.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions