Extract helpers for testing promises to test-utils

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne SavolainenandMikko Aspiala committed 2022-05-11 08:28:11 +03:00
1 parent 395ce7ab49
commit 16b91773ee
4 files changed
+28 -18

No files matched your search

+5 -16
View File
@@ -2,7 +2,8 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import asyncFn, { AsyncFnMock } from "@async-fn/jest";
import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest";
import {
createContainer,
@@ -10,7 +11,9 @@ import {
getInjectionToken,
} from "@ogre-tools/injectable";
import { runManyFor, Runnable } from "./run-many-for";
import type { Runnable } from "./run-many-for";
import { runManyFor } from "./run-many-for";
import { getPromiseStatus } from "../test-utils/get-promise-status";
describe("runManyFor", () => {
describe("given no hierarchy, when running many", () => {
@@ -220,17 +223,3 @@ describe("runManyFor", () => {
});
});
});
const flushPromises = () => new Promise(setImmediate);
const getPromiseStatus = async (promise: Promise<unknown>) => {
const status = { fulfilled: false };
promise.finally(() => {
status.fulfilled = true;
});
await flushPromises();
return status;
};
+5
View File
@@ -0,0 +1,5 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
export const flushPromises = () => new Promise(setImmediate);
@@ -0,0 +1,17 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { flushPromises } from "./flush-promises";
export const getPromiseStatus = async (promise: Promise<unknown>) => {
const status = { fulfilled: false };
promise.finally(() => {
status.fulfilled = true;
});
await flushPromises();
return status;
};
@@ -42,6 +42,7 @@ import namespaceStoreInjectable from "../+namespaces/namespace-store/namespace-s
import clusterFrameContextInjectable from "../../cluster-frame-context/cluster-frame-context.injectable";
import startMainApplicationInjectable from "../../../main/start-main-application/start-main-application.injectable";
import startFrameInjectable from "../../start-frame/start-frame.injectable";
import { flushPromises } from "../../../common/test-utils/flush-promises";
type Callback = (dis: DiContainers) => void | Promise<void>;
@@ -167,8 +168,6 @@ export const getApplicationBuilder = () => {
menuItem.click(undefined, undefined, undefined);
const flushPromises = () => new Promise(setImmediate);
await flushPromises();
},
},