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.keyboard('{Enter}') does not trigger form submission in forms with radio group elements #1378

Closed
vinothkumar-tw opened this issue Jan 16, 2025 · 1 comment

Comments

@vinothkumar-tw
Copy link

vinothkumar-tw commented Jan 16, 2025

  • @testing-library/react version: 16.2.0
  • Testing Framework and version:
    • vitest version: 2.1.2
    • @vitest/ui version: 2.1.2
    • @vitest/coverage-v8 version: 2.1.2
    • @vitejs/plugin-react version: 4.3.2
  • DOM Environment:
    • jsdom version: 24.1.1

Relevant code or config:

<div>
      {showSuccess ? (
        'success'
      ) : (
        <form name="myform" onSubmit={handleSubmit}>
          <label htmlFor="search">Search</label>
          <input type="text" name="search" id="search" />

          {/* // Comment the below code to make test case pass */}
          <div>
            <label>Gender</label>
            <input type="radio" name="gender" value="male" />
            <input type="radio" name="gender" value="female" />
          </div>
        </form>
      )}
</div>
describe('Test Suite', () => {
  test('Test', async () => {
    render(<App />);
    const user = userEvent.setup();
    const input = screen.getByLabelText('Search');

    await user.type(input, 'test');
    await user.keyboard('{Enter}');
    expect(screen.queryByRole('form')).not.toBeInTheDocument();
  });
});

What you did:

  • I attempted to submit the form by using userEvent.keyboard('{Enter}').

What happened:

  • userEvent.keyboard('{Enter}') does not trigger form submission

Reproduction:

https://stackblitz.com/edit/rtl-template-dg4qziej?file=vite.config.ts

Problem description:

Issue: userEvent.keyboard('{Enter}') does not trigger form submission when the form contains radio group elements.
Observation: Using fireEvent.submit successfully triggers form submission under the same conditions.

Suggested solution:

@vinothkumar-tw vinothkumar-tw changed the title @testing-library/user-event / userEvent.keyboard Enter event is not triggered userEvent.keyboard('{Enter}') does not trigger form submission in forms with radio group elements Jan 16, 2025
@vinothkumar-tw
Copy link
Author

i have created an issue in user-event repository. Closing this story testing-library/user-event#1255

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant