From 97fd257e9bb8dd9d88dc41d2619fedfc84985987 Mon Sep 17 00:00:00 2001 From: Nick Floyd Date: Wed, 13 Nov 2024 15:38:59 -0600 Subject: [PATCH] updates tests to use the new v12 fetch-mock apis --- test/integration/smoke.test.ts | 19 +++++++++++-------- test/issues/881-redirect-url.test.ts | 4 ++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/test/integration/smoke.test.ts b/test/integration/smoke.test.ts index 9fed5856..f66981c3 100644 --- a/test/integration/smoke.test.ts +++ b/test/integration/smoke.test.ts @@ -16,10 +16,13 @@ describe("Smoke tests", () => { it("userAgent option", () => { const mock = fetchMock - .sandbox() - .getOnce("https://api.github.com/", (_url, { headers }) => { + .createInstance() + .getOnce("https://api.github.com/", (_url) => { // @ts-ignore headers has wrong typing in fetch-mock 8.3.2 - expect(headers["user-agent"]).toMatch(/^my-app\/1.2.3 /); + expect( + mock.callHistory.calls()[0].options.headers!["user-agent"], + ).toMatch(/^my-app\/1.2.3 /); + // expect(headers["user-agent"]).toMatch(/^my-app\/1.2.3 /); return { ok: true }; }); @@ -27,7 +30,7 @@ describe("Smoke tests", () => { const octokit = new Octokit({ userAgent: "my-app/1.2.3", request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); return octokit.request("/"); @@ -35,12 +38,12 @@ describe("Smoke tests", () => { it("@octokit/plugin-rest-endpoint-methods", () => { const mock = fetchMock - .sandbox() + .createInstance() .getOnce("path:/repos/octocat/hello-world", { ok: true }); const octokit = new Octokit({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); @@ -58,7 +61,7 @@ describe("Smoke tests", () => { it("@octokit/plugin-request-log", () => { const mock = fetchMock - .sandbox() + .createInstance() .getOnce("path:/", { status: 200, body: {} }) .getOnce("path:/", { status: 404, body: {} }, { overwriteRoutes: false }); @@ -72,7 +75,7 @@ describe("Smoke tests", () => { const octokit = new Octokit({ log: consoleStub, request: { - fetch: mock, + fetch: mock.fetchHandler, }, }); diff --git a/test/issues/881-redirect-url.test.ts b/test/issues/881-redirect-url.test.ts index f4d2248b..68d2b029 100644 --- a/test/issues/881-redirect-url.test.ts +++ b/test/issues/881-redirect-url.test.ts @@ -9,7 +9,7 @@ describe("https://github.com/octokit/rest.js/issues/881", () => { "https://issue-881-codeload.github.com/octocat/Hello-World/legacy.tar.gz/master"; const mock = fetchMock - .sandbox() + .createInstance() .headOnce( "https://api.github.com/repos/octocat/Hello-World/tarball/master", { @@ -20,7 +20,7 @@ describe("https://github.com/octokit/rest.js/issues/881", () => { const octokit = new Octokit({ request: { - fetch: mock, + fetch: mock.fetchHandler, }, });