Skip to content

onChange of input is not fired, if userEvent.type is used #676

@wuarmin

Description

@wuarmin

Hey, thank you for this library.

I have following issue and cannot figure out what I'm doing wrong.

"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^13.0.13",
"@testing-library/dom": "^7.30.0",

Relevant code, which causes the issue:

// test of a parent component - the input comes from a sub-component, which uses onChange-event
const input = screen.getByPlaceholderText(/name/i);
const searchButton = screen.getByRole("button", { name: /search/i });

await userEvent.type(input, "Knight", { delay: 500 }); // onChange-event is not fired!!!
userEvent.click(searchButton);
// search-handler cannot place search, because name-input-value is empty
 

fireEvent works

const input = screen.getByPlaceholderText(/name/i);
const searchButton = screen.getByRole("button", { name: /search/i });

fireEvent.change(input, { target: { value: "Knight" } }); // onChange-event is fired!!!
userEvent.click(searchButton);
// search-handler can place the search

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