From bafecb3aabecdf1247cfa61400f8ff97c61dd4fc Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Tue, 28 Nov 2023 19:14:05 -0500 Subject: [PATCH 1/2] test: add test for empty response with json media type Follow-up to #648 --- test/request.test.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/request.test.ts b/test/request.test.ts index fe39cd01a..3c3139e6a 100644 --- a/test/request.test.ts +++ b/test/request.test.ts @@ -1120,4 +1120,27 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w== expect(mock.done()).toBe(true); }); }); + + it("should not error for empty response body and json media type (#649)", () => { + const mock = fetchMock.sandbox().get("path:/", { + status: 200, + body: "", + headers: { + "content-length": "0", + "content-type": "application/json; charset=utf-8", + }, + }); + + expect(request).not.toThrow(); + return request("GET /", { + headers: { + accept: "application/json", + }, + request: { + fetch: mock, + }, + }).then((response) => { + expect(response.data).toEqual(""); + }); + }); }); From 02c662c049369cca17d9a6d1d823844845f0439a Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Tue, 28 Nov 2023 19:29:33 -0500 Subject: [PATCH 2/2] test: remove duplicate test --- test/request.test.ts | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/test/request.test.ts b/test/request.test.ts index 3c3139e6a..b08eeb14e 100644 --- a/test/request.test.ts +++ b/test/request.test.ts @@ -405,12 +405,13 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w== .sandbox() .get("path:/repos/octokit-fixture-org/hello-world/contents/README.md", { status: 500, - body: undefined, + body: "", headers: { "content-type": "application/json", }, }); + expect(request).not.toThrow(); return request("GET /repos/{owner}/{repo}/contents/{path}", { headers: { accept: "content-type: application/json", @@ -1120,27 +1121,4 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w== expect(mock.done()).toBe(true); }); }); - - it("should not error for empty response body and json media type (#649)", () => { - const mock = fetchMock.sandbox().get("path:/", { - status: 200, - body: "", - headers: { - "content-length": "0", - "content-type": "application/json; charset=utf-8", - }, - }); - - expect(request).not.toThrow(); - return request("GET /", { - headers: { - accept: "application/json", - }, - request: { - fetch: mock, - }, - }).then((response) => { - expect(response.data).toEqual(""); - }); - }); });