Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit 9aa09d4

Browse files
authored
Maybe fix flakey AddRemoveThreepid test (#81)
I have no idea why this is flaking. There are warnings about things not being wrapped in act() which may be relevant... this makes the warnings happy, although apparently should not be necessary. testing-library/user-event#906 and testing-library/user-event#497 are depressing reading (making the versions the same didn't help). I think my conclusion might be to do this until we're able to upgrade to the latest testing-library, then re-evaluate. It still may or may not fix the flake.
1 parent d56b9ed commit 9aa09d4

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

test/components/views/settings/AddRemoveThreepids-test.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
66
Please see LICENSE files in the repository root for full details.
77
*/
88

9-
import { render, screen } from "@testing-library/react";
9+
import { render, screen, waitFor } from "@testing-library/react";
1010
import { MatrixClient, ThreepidMedium } from "matrix-js-sdk/src/matrix";
1111
import React from "react";
1212
import userEvent from "@testing-library/user-event";
@@ -218,23 +218,32 @@ describe("AddRemoveThreepids", () => {
218218
await userEvent.type(input, PHONE1_LOCALNUM);
219219

220220
const addButton = screen.getByRole("button", { name: "Add" });
221-
await userEvent.click(addButton);
221+
userEvent.click(addButton);
222+
223+
const continueButton = await screen.findByRole("button", { name: "Continue" });
224+
225+
await expect(continueButton).toHaveAttribute("aria-disabled", "true");
226+
227+
await expect(
228+
await screen.findByText(
229+
`A text message has been sent to +${PHONE1.address}. Please enter the verification code it contains.`,
230+
),
231+
).toBeInTheDocument();
222232

223233
expect(client.requestAdd3pidMsisdnToken).toHaveBeenCalledWith(
224234
"GB",
225235
PHONE1_LOCALNUM,
226236
client.generateClientSecret(),
227237
1,
228238
);
229-
const continueButton = screen.getByRole("button", { name: "Continue" });
230-
231-
expect(continueButton).toHaveAttribute("aria-disabled", "true");
232239

233240
const verificationInput = screen.getByRole("textbox", { name: "Verification code" });
234241
await userEvent.type(verificationInput, "123456");
235242

236243
expect(continueButton).not.toHaveAttribute("aria-disabled", "true");
237-
await userEvent.click(continueButton);
244+
userEvent.click(continueButton);
245+
246+
await waitFor(() => expect(continueButton).toHaveAttribute("aria-disabled", "true"));
238247

239248
expect(client.addThreePidOnly).toHaveBeenCalledWith({
240249
client_secret: client.generateClientSecret(),

0 commit comments

Comments
 (0)