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:
committed by
GitHub
parent
0f783ede5e
commit
a3f5d207de
@@ -21,7 +21,7 @@ import { completeAuthorizationCodeGrant } from "matrix-js-sdk/src/oidc/authorize
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { OidcError } from "matrix-js-sdk/src/oidc/error";
|
||||
import { type BearerTokenResponse } from "matrix-js-sdk/src/oidc/validate";
|
||||
import { defer, type IDeferred, sleep } from "matrix-js-sdk/src/utils";
|
||||
import { sleep } from "matrix-js-sdk/src/utils";
|
||||
import {
|
||||
CryptoEvent,
|
||||
type DeviceVerificationStatus,
|
||||
@@ -85,7 +85,7 @@ describe("<MatrixChat />", () => {
|
||||
const deviceId = "qwertyui";
|
||||
const accessToken = "abc123";
|
||||
const refreshToken = "def456";
|
||||
let bootstrapDeferred: IDeferred<void>;
|
||||
let bootstrapDeferred: PromiseWithResolvers<void>;
|
||||
// reused in createClient mock below
|
||||
const getMockClientMethods = () => ({
|
||||
...mockClientMethodsUser(userId),
|
||||
@@ -248,7 +248,7 @@ describe("<MatrixChat />", () => {
|
||||
{} as ValidatedServerConfig,
|
||||
);
|
||||
|
||||
bootstrapDeferred = defer();
|
||||
bootstrapDeferred = Promise.withResolvers();
|
||||
|
||||
await clearAllModals();
|
||||
});
|
||||
@@ -1513,7 +1513,7 @@ describe("<MatrixChat />", () => {
|
||||
jest.spyOn(MatrixJs, "createClient").mockReturnValue(client);
|
||||
|
||||
// intercept initCrypto and have it block until we complete the deferred
|
||||
const initCryptoCompleteDefer = defer();
|
||||
const initCryptoCompleteDefer = Promise.withResolvers<void>();
|
||||
const initCryptoCalled = new Promise<void>((resolve) => {
|
||||
client.initRustCrypto.mockImplementation(() => {
|
||||
resolve();
|
||||
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
SearchResult,
|
||||
type ISearchResults,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { defer } from "matrix-js-sdk/src/utils";
|
||||
|
||||
import { RoomSearchView } from "../../../../src/components/structures/RoomSearchView";
|
||||
import ResizeNotifier from "../../../../src/utils/ResizeNotifier";
|
||||
@@ -53,7 +52,7 @@ describe("<RoomSearchView/>", () => {
|
||||
});
|
||||
|
||||
it("should show a spinner before the promise resolves", async () => {
|
||||
const deferred = defer<ISearchResults>();
|
||||
const deferred = Promise.withResolvers<ISearchResults>();
|
||||
|
||||
render(
|
||||
<RoomSearchView
|
||||
@@ -267,7 +266,7 @@ describe("<RoomSearchView/>", () => {
|
||||
});
|
||||
|
||||
it("should handle resolutions after unmounting sanely", async () => {
|
||||
const deferred = defer<ISearchResults>();
|
||||
const deferred = Promise.withResolvers<ISearchResults>();
|
||||
|
||||
const { unmount } = render(
|
||||
<MatrixClientContext.Provider value={client}>
|
||||
@@ -291,7 +290,7 @@ describe("<RoomSearchView/>", () => {
|
||||
});
|
||||
|
||||
it("should handle rejections after unmounting sanely", async () => {
|
||||
const deferred = defer<ISearchResults>();
|
||||
const deferred = Promise.withResolvers<ISearchResults>();
|
||||
|
||||
const { unmount } = render(
|
||||
<MatrixClientContext.Provider value={client}>
|
||||
@@ -316,7 +315,7 @@ describe("<RoomSearchView/>", () => {
|
||||
|
||||
it("report error if one is encountered", async () => {
|
||||
const onUpdate = jest.fn();
|
||||
const deferred = defer<ISearchResults>();
|
||||
const deferred = Promise.withResolvers<ISearchResults>();
|
||||
|
||||
render(
|
||||
<MatrixClientContext.Provider value={client}>
|
||||
|
||||
@@ -35,7 +35,6 @@ import {
|
||||
cleanup,
|
||||
} from "jest-matrix-react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { defer } from "matrix-js-sdk/src/utils";
|
||||
|
||||
import {
|
||||
stubClient,
|
||||
@@ -368,7 +367,7 @@ describe("RoomView", () => {
|
||||
it("should not display the timeline when the room encryption is loading", async () => {
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
|
||||
jest.spyOn(cli, "getCrypto").mockReturnValue(crypto);
|
||||
const deferred = defer<boolean>();
|
||||
const deferred = Promise.withResolvers<boolean>();
|
||||
jest.spyOn(cli.getCrypto()!, "isEncryptionEnabledInRoom").mockImplementation(() => deferred.promise);
|
||||
|
||||
const { asFragment, container } = await mountRoomView();
|
||||
|
||||
Reference in New Issue
Block a user