From e8489d556e8aa769ee15f37a01c8ca6a1afdf6a1 Mon Sep 17 00:00:00 2001 From: Andrew Aquino Date: Thu, 11 Jun 2026 16:36:16 -0700 Subject: [PATCH] test: await copy created token button before clicking (#26174) fixes DEVEX-375 Replaces `getByRole` with async `findByRole`, which returns a promise / rejects if no matching element is found after a default timeout of 1000ms Co-written with Coder Agents. Relevant chat responses: [I couldn't repro locally, so I inquired if there was a commit/PR that fixed the flake within the past 3 weeks] >No, this flake has not been fixed. There have been zero commits to `CreateTokenPage`, `CopyButton`, `CodeExample`, or `useClipboard.ts` since the failing CI run (13bf0e11f1, May 20). >`getByRole` is synchronous, so it doesn't wait for the success modal (containing the "Copy code" button) to render after the `createToken()` mutation resolves. When the mutation is slow, the DOM still shows the form (Cancel / Create token), and the query fails. --- site/src/pages/CreateTokenPage/CreateTokenPage.test.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/site/src/pages/CreateTokenPage/CreateTokenPage.test.tsx b/site/src/pages/CreateTokenPage/CreateTokenPage.test.tsx index d1a2daca04..d034ad0d02 100644 --- a/site/src/pages/CreateTokenPage/CreateTokenPage.test.tsx +++ b/site/src/pages/CreateTokenPage/CreateTokenPage.test.tsx @@ -94,7 +94,9 @@ describe("TokenPage", () => { }); await createToken(); - await userEvent.click(screen.getByRole("button", { name: "Copy code" })); + await userEvent.click( + await screen.findByRole("button", { name: "Copy code" }), + ); await waitFor(() => { expect(copiedText).toBe("abcd");