Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/vitest/src/integrations/env/jsdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export default <Environment>{
}

function createCompatRequest(utils: CompatUtils) {
return class Request extends NodeRequest_ {
class Request extends NodeRequest_ {
constructor(...args: [input: RequestInfo, init?: RequestInit]) {
const [input, init] = args
if (init?.body != null) {
Expand All @@ -254,10 +254,11 @@ function createCompatRequest(utils: CompatUtils) {
return instance instanceof NodeRequest_
}
}
return Request
}

function createJSDOMCompatURL(utils: CompatUtils): typeof URL {
return class URL extends NodeURL {
class URL extends NodeURL {
static createObjectURL(blob: any): string {
if (blob instanceof utils.window.Blob) {
const compatBlob = utils.makeCompatBlob(blob)
Expand All @@ -269,7 +270,8 @@ function createJSDOMCompatURL(utils: CompatUtils): typeof URL {
static [Symbol.hasInstance](instance: unknown): boolean {
return instance instanceof NodeURL
}
} as typeof URL
}
return URL
}

interface CompatUtils {
Expand Down
5 changes: 5 additions & 0 deletions test/core/test/environments/jsdom.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ test('URL.createObjectUrl works properly', () => {
}).not.toThrow()
})

test('compat classes preserve their .name property', () => {
expect(URL.name).toBe('URL')
expect(Request.name).toBe('Request')
})

test('jsdom global is exposed', () => {
// @ts-expect-error -- jsdom is not exposed in our types because we use a single tsconfig for all
const dom = jsdom
Expand Down
Loading