From 890c5a5310bd8e36a8cd38cccb4c902a6cce1ba0 Mon Sep 17 00:00:00 2001 From: Iku-turso Date: Mon, 24 Oct 2022 10:38:21 +0300 Subject: [PATCH] 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 Signed-off-by: Iku-turso --- .../get-global-override-for-function.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/common/test-utils/get-global-override-for-function.ts b/src/common/test-utils/get-global-override-for-function.ts index 346bf57db0..238ee5621a 100644 --- a/src/common/test-utils/get-global-override-for-function.ts +++ b/src/common/test-utils/get-global-override-for-function.ts @@ -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, ) => - 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.`, + ); });