From bafecb3aabecdf1247cfa61400f8ff97c61dd4fc Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Tue, 28 Nov 2023 19:14:05 -0500 Subject: [PATCH] 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(""); + }); + }); });