From f2ca33ee1d14c27de984a81d2c2d08cec301519f Mon Sep 17 00:00:00 2001 From: Harshit <106448130+harshit-d3v@users.noreply.github.com> Date: Thu, 17 Sep 2026 00:55:46 +0530 Subject: [PATCH] fix(jsdom): keep Blob bytes on jsdom 28+ jsdom 28 renamed the private `_buffer` field to `_bytes`, so `makeCompatBlob` read `undefined` and every Blob or File used as a request body arrived as the string "undefined". --- packages/vitest/src/integrations/env/jsdom.ts | 5 +++-- test/unit/test/environments/jsdom.spec.ts | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/vitest/src/integrations/env/jsdom.ts b/packages/vitest/src/integrations/env/jsdom.ts index b37232883eb9..ffa661180d86 100644 --- a/packages/vitest/src/integrations/env/jsdom.ts +++ b/packages/vitest/src/integrations/env/jsdom.ts @@ -321,8 +321,9 @@ function createCompatUtils(window: DOMWindow): CompatUtils { return nodeFormData }, makeCompatBlob(blob: Blob) { - const buffer = (blob as any)[implSymbol]._buffer - return new NodeBlob_([buffer], { type: blob.type }) + const impl = (blob as any)[implSymbol] + // jsdom 28 renamed `_buffer` to `_bytes` + return new NodeBlob_([impl._bytes ?? impl._buffer], { type: blob.type }) }, } return utils diff --git a/test/unit/test/environments/jsdom.spec.ts b/test/unit/test/environments/jsdom.spec.ts index bac68eea1918..b61a0af842db 100644 --- a/test/unit/test/environments/jsdom.spec.ts +++ b/test/unit/test/environments/jsdom.spec.ts @@ -182,6 +182,13 @@ describe('FormData', () => { expect(retrievedBlob).toBeInstanceOf(File) }) + + test('keeps Blob bytes when used as a Request body', async () => { + const blob = new Blob(['hello world'], { type: 'text/plain' }) + const request = new Request('http://localhost/', { method: 'POST', body: blob }) + + expect(await request.text()).toBe('hello world') + }) }) test('DOM APIs accept AbortController', () => {