aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/fetch.test.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-01 23:27:53 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-01 23:27:53 -0800
commit425f4b0de1b7c853606f4bcb936fa6597202a8ba (patch)
tree9899feae46003c3ace8a6a013d94dd1a83dac7c9 /test/bun.js/fetch.test.js
parent7b70ed52fafa75421c9bb6119b3d40571536cb75 (diff)
downloadbun-425f4b0de1b7c853606f4bcb936fa6597202a8ba.tar.gz
bun-425f4b0de1b7c853606f4bcb936fa6597202a8ba.tar.zst
bun-425f4b0de1b7c853606f4bcb936fa6597202a8ba.zip
[fetch] Add test that invalid json rejects promise
Diffstat (limited to 'test/bun.js/fetch.test.js')
-rw-r--r--test/bun.js/fetch.test.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/bun.js/fetch.test.js b/test/bun.js/fetch.test.js
index 519d6bbdd..af5de1b5a 100644
--- a/test/bun.js/fetch.test.js
+++ b/test/bun.js/fetch.test.js
@@ -160,6 +160,28 @@ function testBlobInterface(blobbyConstructor, hasBlobFn) {
if (withGC) gc();
});
+ it(`${
+ jsonObject.hello === true ? "latin1" : "utf16"
+ } arrayBuffer -> invalid json${
+ withGC ? " (with gc) " : ""
+ }`, async () => {
+ if (withGC) gc();
+ var response = blobbyConstructor(
+ new TextEncoder().encode(
+ JSON.stringify(jsonObject) + " NOW WE ARE INVALID JSON",
+ ),
+ );
+ if (withGC) gc();
+ var failed = false;
+ try {
+ await response.json();
+ } catch (e) {
+ failed = true;
+ }
+ expect(failed).toBe(true);
+ if (withGC) gc();
+ });
+
it(`${jsonObject.hello === true ? "latin1" : "utf16"} text${
withGC ? " (with gc) " : ""
}`, async () => {