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:
parent
e860c388f1
commit
5b8edb6c88
@ -6,9 +6,7 @@ import type { Injectable } from "@ogre-tools/injectable";
|
|||||||
import { getGlobalOverride } from "./get-global-override";
|
import { getGlobalOverride } from "./get-global-override";
|
||||||
import { camelCase } from "lodash/fp";
|
import { camelCase } from "lodash/fp";
|
||||||
|
|
||||||
export const getGlobalOverrideForFunction = (
|
export const getGlobalOverrideForFunction = (injectable: Injectable<Function, any, any>) => (
|
||||||
injectable: Injectable<Function, any, any>,
|
|
||||||
) =>
|
|
||||||
getGlobalOverride(injectable, () => (...args: any[]) => {
|
getGlobalOverride(injectable, () => (...args: any[]) => {
|
||||||
console.warn(
|
console.warn(
|
||||||
`Tried to invoke a function "${injectable.id}" without override. The args were:`,
|
`Tried to invoke a function "${injectable.id}" without override. The args were:`,
|
||||||
@ -16,10 +14,7 @@ export const getGlobalOverrideForFunction = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Tried to invoke a function "${
|
`Tried to invoke a function "${injectable.id}" without override. Add eg. "di.override(${camelCase(injectable.id)}Mock)" to the unit test interested in this.`,
|
||||||
injectable.id
|
|
||||||
}" without override. Add eg. "di.override(${camelCase(
|
|
||||||
injectable.id,
|
|
||||||
)}Mock)" to the unit test interested in this.`,
|
|
||||||
);
|
);
|
||||||
});
|
})
|
||||||
|
);
|
||||||
|
|||||||
@ -2,16 +2,16 @@
|
|||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* 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 {
|
export interface GlobalOverride<Instance extends Token, Token, Param> {
|
||||||
injectable: Injectable<any, any, any>;
|
injectable: Injectable<Instance, Token, Param>;
|
||||||
overridingInstantiate: any;
|
overridingInstantiate: Instantiate<Instance, Param>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getGlobalOverride = <T extends Injectable<any, any, any>>(
|
export const getGlobalOverride = <Instance extends Token, Token, Param>(
|
||||||
injectable: T,
|
injectable: Injectable<Instance, Token, Param>,
|
||||||
overridingInstantiate: T["instantiate"],
|
overridingInstantiate: (typeof injectable)["instantiate"],
|
||||||
) => ({
|
) => ({
|
||||||
injectable,
|
injectable,
|
||||||
overridingInstantiate,
|
overridingInstantiate,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user