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

Firefox: userEvent.click does not submit forms #1075

Open
anilanar opened this issue Nov 9, 2022 · 8 comments
Open

Firefox: userEvent.click does not submit forms #1075

anilanar opened this issue Nov 9, 2022 · 8 comments
Labels
bug Something isn't working needs investigation Someone has to do research on this

Comments

@anilanar
Copy link

anilanar commented Nov 9, 2022

Reproduction example

https://codesandbox.io/s/nervous-microservice-nmm3h7?file=/src/index.js

Prerequisites

  1. Use Firefox, not jsdom.
  2. Render a form with an onSubmit handler and a button inside the form such as <button type="submit" />.
  3. Use userEvent.click to click the button in the form.

Expected behavior

Form's onSubmit handler should trigger.

Actual behavior

Form's onSubmit handler does not trigger.

User-event version

14.4.3

Environment

Firefox 106.0.2 (64-bit) Linux

Additional context

No response

@anilanar anilanar added bug Something isn't working needs assessment This needs to be looked at by a team member labels Nov 9, 2022
@anilanar
Copy link
Author

I believe this bug affects more than it looks, also in chromiums, but I cannot prove it.

@anilanar
Copy link
Author

Our chromatic interaction tests that runs in chrome (or chromium, not sure if headless or not), using storybook play functions, stopped working after upgrading from 14.2.1 to 14.4.3 due to clicks not triggering submit events for forms. Not exactly sure what version of chrome/chromium and I couldn't reproduce it locally with chrome/chromium, but could reproduce it with Firefox as you can see above.

Downgrading to 14.3.0 seems to fix the issue.

@ph-fritsche
Copy link
Member

Thanks for reporting this.

Maybe this is somehow related to #1002
We're working on changing our test environment. Hopefully this will allow us to tackle these issues. See #1019

@ph-fritsche ph-fritsche added needs investigation Someone has to do research on this and removed needs assessment This needs to be looked at by a team member labels Nov 14, 2022
@anilanar
Copy link
Author

anilanar commented Nov 14, 2022

@ph-fritsche This issue is introduced with 14.4.0 (#1003 or #1009?) and is not reproducible in 14.3.0, if that helps.

@mscrivo
Copy link

mscrivo commented Apr 13, 2023

Seeing similar issues here with userEvent.pointer. We have a test that clicks and resizes and resizable drawer and the test was checking whether the size has changed, and it never does now with 14.4+, but worked fine on 14.3 and below.

@sergei-maertens
Copy link

sergei-maertens commented Nov 16, 2023

I'm seeing this behaviour too but it's inconsistent - in some storybook tests userEvent.click(...) to submit a form works fine, for others I need to fall back on fireEvent and some other crutches to prevent my tests from asserting things too soon because my form submit handler is still executing 😕

Seeing it on testing-library/user-events 14.4.3 but also on the latest 14.5.1, in combination with Storybook 7.3.2

sergei-maertens added a commit to open-formulieren/formio-builder that referenced this issue Nov 17, 2023
This was an (unsuccesful) attempt to make userEvent.click(submitButton)
actually submit the form(s) on Firefox, but it is bugged in testing
library itself, see:
testing-library/user-event#1075
sergei-maertens added a commit to open-formulieren/formio-builder that referenced this issue Nov 17, 2023
This was an (unsuccesful) attempt to make userEvent.click(submitButton)
actually submit the form(s) on Firefox, but it is bugged in testing
library itself, see:
testing-library/user-event#1075
@kasperpeulen
Copy link

Workaround:

export const Submitting = {
  play: async ({ canvasElement }) => {
    const canvas = within(canvasElement);
    const submitButton = canvas.getByRole('button', { name: /Submit/i });
-   await userEvent.click(submitButton);
+   await fireEvent.click(submitButton);
  },
};

But fireEvent does a lot less than userEvent, so you might have to manually do the stuff that userEvent does (focus, hover etc).

@ph-fritsche I don't really understand why this works, because I thought userEvent uses fireEvent under the hood.

@nomoreyesterday
Copy link

nomoreyesterday commented May 1, 2024

export const EmptySubmit: Story = {
  play: async ({ canvasElement }) => {
    const canvas = within(canvasElement);
    const SubmitButton = canvas.getByRole('button', { name: /submit/i });
    await expect(SubmitButton).toBeInTheDocument();
    await fireEvent.click(SubmitButton)
    expect(canvas.getByText(/Username must be at least 2 characters./i)).toBeInTheDocument();
  },

image

fireEvent only didn't work for me but if add userEvent that's work

export const EmptySubmit: Story = {
  play: async ({ canvasElement }) => {
    const canvas = within(canvasElement);
    const SubmitButton = canvas.getByRole('button', { name: /submit/i });
    await expect(SubmitButton).toBeInTheDocument();
    await fireEvent.click(SubmitButton)
+   await userEvent.click(SubmitButton)
    expect(canvas.getByText(/Username must be at least 2 characters./i)).toBeInTheDocument();
  },

image

edit : userEvent work in google chrome
but firefox still error

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 investigation Someone has to do research on this
Projects
None yet
Development

No branches or pull requests

6 participants