Skip to content

Flaky test: pairing queue focus assertion is not wrapped in waitFor #694

Closed

Description

@enaboapps

src/App.test.tsx → "handles simultaneous pairing requests without discarding the queue" fails intermittently on CI (Linux, full suite in parallel) while passing consistently locally.

Observed on the CI run for #693, a two-file diff touching only src/settings/, which cannot affect this test:

FAIL src/App.test.tsx > Switchify PC shell > handles simultaneous pairing requests without discarding the queue
Error: expect(element).toHaveFocus()

The same test passed 10/10 locally in isolation on main.

Cause

The final assertion is not wrapped in waitFor:

await waitFor(() => expect(screen.queryByRole("heading", { name: "Galaxy" })).not.toBeInTheDocument());
expect(approve).toHaveBeenCalledWith("pair-2");
expect(screen.getByRole("heading", { name: "Pixel" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Reject pairing request from Pixel, code 111111" })).toHaveFocus();

Focus is moved by an effect in PairingDialog (src/App.tsx, the dialogRef.current?.querySelector<HTMLButtonElement>("button:not(:disabled)")?.focus() effect). The preceding waitFor only guarantees the removed heading is gone — it does not guarantee the focus effect for the re-rendered dialog has run. Under CI load the assertion can observe the intermediate state.

Note the earlier focus assertion in the same test is correctly wrapped:

await waitFor(() => expect(dialog).toHaveFocus());

Fix

Wrap the final focus assertion in waitFor to match. Worth a scan for the same unwrapped-toHaveFocus pattern elsewhere in the suite.

This is a test-only defect; the application focus behavior itself is correct.

Activity

  1. added 3 commits that reference this issue on Sep 8, 2026
    3cb30ee
    60d5512
    ad9e03b
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