From 425f4b0de1b7c853606f4bcb936fa6597202a8ba Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Thu, 1 Dec 2022 23:27:53 -0800 Subject: [fetch] Add test that invalid json rejects promise --- test/bun.js/fetch.test.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/bun.js/fetch.test.js') 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 () => { -- cgit v1.2.3