mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
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:
parent
395ce7ab49
commit
16b91773ee
@ -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
src/common/test-utils/flush-promises.ts
Normal file
5
src/common/test-utils/flush-promises.ts
Normal 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);
|
||||
17
src/common/test-utils/get-promise-status.ts
Normal file
17
src/common/test-utils/get-promise-status.ts
Normal file
@ -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();
|
||||
},
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user