Skip to content

Commit d1c3ecc

Browse files
authored
fix(jsdom): fix Request with Blob body on jsdom 28+ (#11295)
1 parent e8e556f commit d1c3ecc

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎packages/vitest/src/integrations/env/jsdom.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,9 @@ function createCompatUtils(window: DOMWindow): CompatUtils {
321321
return nodeFormData
322322
},
323323
makeCompatBlob(blob: Blob) {
324-
const buffer = (blob as any)[implSymbol]._buffer
325-
return new NodeBlob_([buffer], { type: blob.type })
324+
const impl = (blob as any)[implSymbol]
325+
// jsdom 28 renamed `_buffer` to `_bytes`
326+
return new NodeBlob_([impl._bytes ?? impl._buffer], { type: blob.type })
326327
},
327328
}
328329
return utils

‎test/unit/test/environments/jsdom.spec.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ describe('FormData', () => {
182182

183183
expect(retrievedBlob).toBeInstanceOf(File)
184184
})
185+
186+
test('keeps Blob bytes when used as a Request body', async () => {
187+
const blob = new Blob(['hello world'], { type: 'text/plain' })
188+
const request = new Request('http://localhost/', { method: 'POST', body: blob })
189+
190+
expect(await request.text()).toBe('hello world')
191+
})
185192
})
186193

187194
test('DOM APIs accept AbortController', () => {

0 commit comments

Comments
 (0)