79562298

Date: 2025-04-08 14:21:36
Score: 1
Natty:
Report link

In my case userEvent.type(input, "abc{enter}"); didn't work because I need to modify and validate the value before submitting it. This worked.

test("should submit when pressing enter", async () => {
  const handleSubmit = jest.fn();
  const { getByLabelText } = render(<App handleSubmit={handleSubmit} />);
  const input = getByLabelText("Name:");

  fireEvent.change(input, { target: { value: "abc" } });
  await userEvent.type(input, '{enter}');

  expect(handleSubmit).toHaveBeenCalled();
});
Reasons:
  • Blacklisted phrase (0.5): I need
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Georgi Dzhangozov