Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

userEvent.click on <button type="submit" /> does not trigger form onSubmit() method #1196

Open
cjOne7 opened this issue Feb 14, 2024 · 2 comments
Labels
bug Something isn't working needs assessment This needs to be looked at by a team member

Comments

@cjOne7
Copy link

cjOne7 commented Feb 14, 2024

Reproduction example

https://codesandbox.io/p/devbox/uservent-click-test-showcase-qdnhsg?file=%2Fsrc%2F__tests__%2FMultistemForm.test.tsx%3A29%2C1

Prerequisites

  1. Render a <form /> with a <button type="submit /> inside.
  2. Attempt to submit the form using userEvent.click().
  3. Forbid to pass onSubmit method as props.

Expected behavior

Expected the form to be submitted, its onSubmit() handle method will be called, button with text Previous will be appeared and test passed.
To run test just type npm run test in the console
image

Actual behavior

Test failed, button with text Previous didn't find, because form has not been submitted. But this example works perfectly:

    await waitFor(() => {
      fireEvent.submit(getByText("Previous"));
    });

User-event version

14.5.2

Environment

"react-dom": "18.2.0",
"react": "18.2.0",

"@testing-library/jest-dom": "6.4.2",
"@testing-library/react": "14.2.1",
"@testing-library/user-event": "14.5.2",
"@types/react-dom": "18.2.19",
"@types/react": "18.2.55",
"@vitejs/plugin-react": "4.2.1",
"@vitest/coverage-v8": "1.2.2",
"jsdom": "24.0.0",
"typescript": "5.3.3",
"vite": "5.1.0",
"vitest": "1.2.2"

Additional context

This issue has been reported before #1032

@cjOne7 cjOne7 added bug Something isn't working needs assessment This needs to be looked at by a team member labels Feb 14, 2024
@cjOne7
Copy link
Author

cjOne7 commented Apr 29, 2024

Still waiting for fix...

@aKaradzhov97
Copy link

I also faced this issue. And for some reason, fireEvent.submit() doesn't help in my case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs assessment This needs to be looked at by a team member
Projects
None yet
Development

No branches or pull requests

2 participants