Switch from defer to Promise.withResolvers (#29078)

* Switch from defer to PromiseWithResolvers

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Add modernizr check

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

---------

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski
2025-05-08 10:03:43 +00:00
committed by GitHub
parent 0f783ede5e
commit a3f5d207de
34 changed files with 61 additions and 89 deletions
@@ -9,7 +9,6 @@ import React from "react";
import { render, screen, waitFor } from "jest-matrix-react";
import userEvent from "@testing-library/user-event";
import { mocked } from "jest-mock";
import { defer } from "matrix-js-sdk/src/utils";
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
import { createTestClient, withClientContextRenderOptions } from "../../../../../test-utils";
@@ -72,7 +71,7 @@ describe("<DeleteKeyStoragePanel />", () => {
});
it("should wait with button disabled while setEnabled runs", async () => {
const setEnabledDefer = defer();
const setEnabledDefer = Promise.withResolvers<void>();
mocked(useKeyStoragePanelViewModel).mockReturnValue({
setEnabled: jest.fn().mockReturnValue(setEnabledDefer.promise),
@@ -7,7 +7,7 @@
import React from "react";
import { type MatrixClient } from "matrix-js-sdk/src/matrix";
import { sleep, defer } from "matrix-js-sdk/src/utils";
import { sleep } from "matrix-js-sdk/src/utils";
import { render, screen } from "jest-matrix-react";
import userEvent from "@testing-library/user-event";
@@ -33,7 +33,7 @@ describe("<ResetIdentityPanel />", () => {
// We need to pause the reset so that we can check that it's providing
// feedback to the user that something is happening.
const { promise: resetEncryptionPromise, resolve: resolveResetEncryption } = defer();
const { promise: resetEncryptionPromise, resolve: resolveResetEncryption } = Promise.withResolvers<void>();
jest.spyOn(matrixClient.getCrypto()!, "resetEncryption").mockReturnValue(resetEncryptionPromise);
const continueButton = screen.getByRole("button", { name: "Continue" });