Skip to content

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

@mzietlow

Description

@mzietlow
  • @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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions