Skip to content

Commit

Permalink
actually fix it
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Jul 3, 2024
1 parent d55ec19 commit 58d022d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions packages/shared/src/cachedFetch.test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 () => {
Expand Down

0 comments on commit 58d022d

Please sign in to comment.