From 58d022d2a8f3c891dc09d67f358f4c67f0ecba9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Wed, 3 Jul 2024 18:50:19 +0200 Subject: [PATCH] actually fix it --- packages/shared/src/cachedFetch.test.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/shared/src/cachedFetch.test.ts b/packages/shared/src/cachedFetch.test.ts index f610f3dc..8768f69d 100644 --- a/packages/shared/src/cachedFetch.test.ts +++ b/packages/shared/src/cachedFetch.test.ts @@ -1,5 +1,8 @@ import assert from "assert"; -import { cachedFetch, resetCache } from "./cachedFetch"; +import type { + cachedFetch as cachedFetchStatic, + resetCache as resetCacheStatic, +} from "./cachedFetch"; class Response { public status: number; @@ -21,19 +24,22 @@ const failedResponse = new Response(500, "error"); const successResponse = new Response(200, "ok"); describe("cachedFetch", () => { + let cachedFetch: typeof cachedFetchStatic; + let resetCache: typeof resetCacheStatic; let mockFetch: jest.Mock; beforeEach(() => { - mockFetch = jest.fn(async (url: string) => { - return successResponse; - }); - jest.mock("undici", () => ({ - fetch: mockFetch, - })); + jest.mock("undici"); + + mockFetch = require("undici").fetch; + mockFetch.mockReturnValue(successResponse); + + ({ cachedFetch, resetCache } = require("./cachedFetch")); }); afterEach(() => { resetCache(); + mockFetch.mockClear(); }); it("should return a successful response", async () => {