mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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.
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user