Skip to content

Flaky Tests with user.type (missing characters) #1419

Open

Description

@malte-dallmeyer
  • @testing-library/react version: 16.3.0
  • Testing Framework and version: vitest@3.2.4
  • DOM Environment: jsdom@27.0.0

Relevant code or config:

import {
  Dialog,
  DialogBody,
  DialogContent,
  DialogSurface,
  DialogTitle,
} from "@fluentui/react-components";

const DialogWithInput = () => {
  return (
    <Dialog open={true}>
      <DialogSurface>
        <DialogBody>
          <DialogTitle>Flaky RTL Test MWE</DialogTitle>
          <DialogContent>
            <input type="text" />
          </DialogContent>
        </DialogBody>
      </DialogSurface>
    </Dialog>
  );
}

describe("DialogWithInput", () => {
  it("accepts long text", async () => {
    const user = userEvent.setup();
    render(<DialogWithInput />);

    const textbox = await screen.findByRole("textbox");

    await user.type(textbox, "why-won't-you-type-this?");

    await waitFor(async () =>
      expect(textbox).toHaveValue("why-won't-you-type-this?")
    );
  });
});

What you did:

I tested whether a user could correctly modify a textbox using await user.type(<textbox>, <text-value>). The textbox is embedded inside a simple Fluent UI v9 Dialog component.

What happened:

user.type did not type the full text-value leading to a test failure:

Expected the element to have value:
  why-won't-you-type-this?
Received:
  why-wo

Reproduction:

Repo: https://github.com/[mzietlow/flaky-rtl-tests
Stackblitz (although I did not try it on stackblitz): https://stackblitz.com/github/mzietlow/flaky-rtl-tests

Problem description:

Tests are flaky. Especially on CI, where user.type tends to produce even fewer characters.

Suggested solution:

user.type should type all characters.

I was able to pass { delay: null } as a temporary workaround, but that is not really a solution.

Activity

  1. changed the title [-]Flaky Tests with userEvent.type (missing characters)[/-] [+]Flaky Tests with user.type (missing characters)[/+] on Oct 6, 2025
  2. MatanBobi commented on Oct 7, 2025

    @MatanBobi
    Member

    Hi @mzietlow, thanks for opening this.
    I actually tried to reproduce it on our reproduction repo and looks like the test is passing, might be something related to other dependencies you have?
    https://stackblitz.com/edit/rtl-template-xtnzzhex?file=src%2FDialogWithInput.test.tsx

  3. malte-dallmeyer commented on Oct 7, 2025

    @malte-dallmeyer
    Author

    Hi @MatanBobi, thanks for checking. I noticed you used happy-dom in your reproduction, while we’re running tests with jsdom. I tried with happy-dom as well and couldn’t reproduce the issue with it. However, I was able to reproduce it on my private machine (other than my machine at work) inside WSL2 with jsdom by increasing the input length, for example:

    await user.type(textbox, "why-won't-you-type-this?".repeat(4));

    Could you try running it with jsdom?

  4. beanscg commented on Jun 9, 2026

    @beanscg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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