From cad10893e328c0744d70a6a9a48a1cc85555b145 Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Tue, 3 Nov 2026 01:36:12 +0100 Subject: [PATCH] test: wait for the send confirmation to take focus before pressing Escape --- components/email/__tests__/composer-a11y.test.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/email/__tests__/composer-a11y.test.tsx b/components/email/__tests__/composer-a11y.test.tsx index e69492e89..bdec82551 100644 --- a/components/email/__tests__/composer-a11y.test.tsx +++ b/components/email/__tests__/composer-a11y.test.tsx @@ -444,7 +444,10 @@ describe('confirm before sending (MO-16)', () => { fireEvent.keyDown(screen.getByTestId('composer-subject'), { key: 'Enter', ctrlKey: true }); const dialog = await screen.findByRole('alertdialog'); - fireEvent.keyDown(dialog, { key: 'Escape' }); + // The dialog takes the focus in the same effect that starts listening + // for Escape, which can run after the dialog is already in the DOM. + await waitFor(() => expect(dialog).toContainElement(document.activeElement as HTMLElement)); + fireEvent.keyDown(document.activeElement!, { key: 'Escape' }); await waitFor(() => expect(screen.queryByRole('alertdialog')).toBeNull()); await act(async () => {}); expect(onSend).not.toHaveBeenCalled();