Skip to content

fireEvent.keyPress is not working (ignored or not being triggered) #405

Closed
@maufarinelli

Description

@maufarinelli
  • DOM Testing Library version: "@testing-library/dom": "^6.10.1" and "@testing-library/react": "^9.3.2",`
  • node version: v12.13.1`
  • npm (or yarn) version: yarn 1.19.1`

Relevant code or config:

const { container } = render(<ModelsForm />);
const input = (container as HTMLDivElement).querySelector('input');

fireEvent.change(input, { target: { value: 'test' } });
fireEvent.keyPress(input, { key: 'Enter', code: 13 });

What you did:

I am trying to test a small component which contains an input type="text"

If I fireEvent.change(input, { target: { value: 'test' } }); I can expect its value and it is changed to test as expected

But if I fireEvent.keyPress(input, { key: 'Enter', code: 13 });, my mocked function is never called

What happened:

fireEvent.keyPress(input, { key: 'Enter', code: 13 }); mocked function is never called. Looks like it ignores the event

Reproduction:

https://codesandbox.io/s/react-testing-library-demo-2l41s

Problem description:

fireEvent keyPress is not working

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