Skip to content

Commit bafecb3

Browse files
committed
test: add test for empty response with json media type
Follow-up to #648
1 parent 02b5723 commit bafecb3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/request.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,4 +1120,27 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
11201120
expect(mock.done()).toBe(true);
11211121
});
11221122
});
1123+
1124+
it("should not error for empty response body and json media type (#649)", () => {
1125+
const mock = fetchMock.sandbox().get("path:/", {
1126+
status: 200,
1127+
body: "",
1128+
headers: {
1129+
"content-length": "0",
1130+
"content-type": "application/json; charset=utf-8",
1131+
},
1132+
});
1133+
1134+
expect(request).not.toThrow();
1135+
return request("GET /", {
1136+
headers: {
1137+
accept: "application/json",
1138+
},
1139+
request: {
1140+
fetch: mock,
1141+
},
1142+
}).then((response) => {
1143+
expect(response.data).toEqual("");
1144+
});
1145+
});
11231146
});

0 commit comments

Comments
 (0)