Skip to content

Commit 506a9fd

Browse files
authored
fix(jsdom): cloned request is an instance of Request (#8985)
1 parent b6de72d commit 506a9fd

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ function createCompatRequest(utils: CompatUtils) {
249249
super(...args)
250250
}
251251
}
252+
253+
static [Symbol.hasInstance](instance: unknown): boolean {
254+
return instance instanceof NodeRequest_
255+
}
252256
}
253257
}
254258

@@ -261,6 +265,10 @@ function createJSDOMCompatURL(utils: CompatUtils): typeof URL {
261265
}
262266
return NodeURL.createObjectURL(blob)
263267
}
268+
269+
static [Symbol.hasInstance](instance: unknown): boolean {
270+
return instance instanceof NodeURL
271+
}
264272
} as typeof URL
265273
}
266274

test/core/test/environments/jsdom.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ test('Fetch API accepts other APIs', async () => {
3838
const searchParams = new URLSearchParams()
3939
searchParams.set('key', 'value')
4040
expect.soft(() => new Request('http://localhost', { method: 'POST', body: searchParams })).not.toThrowError()
41+
42+
const clone = request.clone()
43+
expect.soft(clone).toBeInstanceOf(Request)
4144
})
4245

4346
test('fetch api doesnt override the init object', () => {

0 commit comments

Comments
 (0)