1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fixup getGlobalOverride

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2023-03-02 11:01:44 -05:00
parent e860c388f1
commit 5b8edb6c88
2 changed files with 11 additions and 16 deletions

View File

@ -6,9 +6,7 @@ import type { Injectable } from "@ogre-tools/injectable";
import { getGlobalOverride } from "./get-global-override";
import { camelCase } from "lodash/fp";
export const getGlobalOverrideForFunction = (
injectable: Injectable<Function, any, any>,
) =>
export const getGlobalOverrideForFunction = (injectable: Injectable<Function, any, any>) => (
getGlobalOverride(injectable, () => (...args: any[]) => {
console.warn(
`Tried to invoke a function "${injectable.id}" without override. The args were:`,
@ -16,10 +14,7 @@ export const getGlobalOverrideForFunction = (
);
throw new Error(
`Tried to invoke a function "${
injectable.id
}" without override. Add eg. "di.override(${camelCase(
injectable.id,
)}Mock)" to the unit test interested in this.`,
`Tried to invoke a function "${injectable.id}" without override. Add eg. "di.override(${camelCase(injectable.id)}Mock)" to the unit test interested in this.`,
);
});
})
);

View File

@ -2,16 +2,16 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { Injectable } from "@ogre-tools/injectable";
import type { Injectable, Instantiate } from "@ogre-tools/injectable";
export interface GlobalOverride {
injectable: Injectable<any, any, any>;
overridingInstantiate: any;
export interface GlobalOverride<Instance extends Token, Token, Param> {
injectable: Injectable<Instance, Token, Param>;
overridingInstantiate: Instantiate<Instance, Param>;
}
export const getGlobalOverride = <T extends Injectable<any, any, any>>(
injectable: T,
overridingInstantiate: T["instantiate"],
export const getGlobalOverride = <Instance extends Token, Token, Param>(
injectable: Injectable<Instance, Token, Param>,
overridingInstantiate: (typeof injectable)["instantiate"],
) => ({
injectable,
overridingInstantiate,