mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make global overrides for functions log args of the call for devability
Also make the thrown error suggest how to fix the problem. Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
parent
1eb45ac1a4
commit
890c5a5310
@ -4,10 +4,22 @@
|
||||
*/
|
||||
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>,
|
||||
) =>
|
||||
getGlobalOverride(injectable, () => () => {
|
||||
throw new Error(`Tried to invoke a function "${injectable.id}" without override`);
|
||||
getGlobalOverride(injectable, () => (...args: any[]) => {
|
||||
console.warn(
|
||||
`Tried to invoke a function "${injectable.id}" without override. The args were:`,
|
||||
args,
|
||||
);
|
||||
|
||||
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.`,
|
||||
);
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user