Skip to content

Commit

Permalink
fix: don't bind global classes
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed May 20, 2022
1 parent fa066cb commit 2556f1b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/vitest/src/integrations/env/utils.ts
Expand Up @@ -26,6 +26,10 @@ export function getWindowKeys(global: any, win: any) {
return keys
}

function isClassLikeName(name: string) {
return name[0] === name[0].toUpperCase()
}

interface PopulateOptions {
bindFunctions?: boolean
}
Expand All @@ -40,7 +44,7 @@ export function populateGlobal(global: any, win: any, options: PopulateOptions =

const overrideObject = new Map<string | symbol, any>()
for (const key of keys) {
const bindedFunction = bindFunctions && typeof win[key] === 'function' && win[key].bind(win)
const bindedFunction = bindFunctions && typeof win[key] === 'function' && !isClassLikeName(key) && win[key].bind(win)
Object.defineProperty(global, key, {
get() {
if (overrideObject.has(key))
Expand Down
6 changes: 6 additions & 0 deletions test/core/test/dom.test.ts
Expand Up @@ -126,3 +126,9 @@ it('globals are the same', () => {
expect(window.globalThis.Blob).toBe(globalThis.Blob)
expect(Blob).toBe(globalThis.Blob)
})

it('can extend global class', () => {
class SuperBlob extends Blob {}

expect(SuperBlob).toBeDefined()
})

0 comments on commit 2556f1b

Please sign in to comment.