From f5c379e18921e677f633691898585ab1faaf5b0f Mon Sep 17 00:00:00 2001 From: Refringe Date: Mon, 30 Oct 2023 11:46:10 -0400 Subject: [PATCH] Mocks some logger methods to prevent actual execution. --- project/tests/helpers/ItemHelper.test.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/project/tests/helpers/ItemHelper.test.ts b/project/tests/helpers/ItemHelper.test.ts index 645fc47c..e886e7ae 100644 --- a/project/tests/helpers/ItemHelper.test.ts +++ b/project/tests/helpers/ItemHelper.test.ts @@ -312,12 +312,18 @@ describe("ItemHelper", () => const parentId = container.resolve("HashUtil").generate(); - const loggerWarningSpy = vi.spyOn((itemHelper as any).logger, "warning"); + // Spy on the logger's warning method and mock its implementation to prevent it from being actually called. + const loggerWarningSpy = vi.spyOn((itemHelper as any).logger, "warning").mockImplementation(() => + {}); itemHelper.generateItemsFromStackSlot(ammoBox[1], parentId); expect(loggerWarningSpy).toHaveBeenCalled(); + + // Restore the original behavior + loggerWarningSpy.mockRestore(); }); + }); describe("getItems", () => @@ -671,9 +677,14 @@ describe("ItemHelper", () => _tpl: "" }; + // Mock the logger's error method to prevent it from being actually called. + const loggerErrorSpy = vi.spyOn((itemHelper as any).logger, "error").mockImplementation(() => + {}); + // Cast the method to any to allow access to private/protected method. const result = (itemHelper as any).getRepairableItemQualityValue(weapon, repairable, item); + expect(loggerErrorSpy).toHaveBeenCalled(); expect(result).toBe(1); });