Skip to content

Commit

Permalink
fix: allow accessing Audio, Option and private jsdom props on global (#…
Browse files Browse the repository at this point in the history
…1443)

* fix: allow accessing Audio, Option on global

* chore: allow private jsdom properties on globalThis
  • Loading branch information
sheremet-va committed Jun 9, 2022
1 parent 03c7cf6 commit 95ded47
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/vitest/src/integrations/env/jsdom-keys.ts
Expand Up @@ -162,6 +162,8 @@ const LIVING_KEYS = [

// not specified in docs, but is available
'Image',
'Audio',
'Option',
]

const OTHER_KEYS = [
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/integrations/env/utils.ts
Expand Up @@ -15,7 +15,7 @@ const skipKeys = [
export function getWindowKeys(global: any, win: any) {
const keys = new Set(KEYS.concat(Object.getOwnPropertyNames(win))
.filter((k) => {
if (k.startsWith('_') || skipKeys.includes(k))
if (skipKeys.includes(k))
return false
if (k in global)
return allowRewrite.includes(k)
Expand Down
6 changes: 5 additions & 1 deletion test/core/test/dom.test.ts
Expand Up @@ -27,10 +27,14 @@ it('dispatchEvent doesn\'t throw', () => {
expect(() => target.dispatchEvent(event)).not.toThrow()
})

it('Image works as expected', () => {
it('Non-public "live" keys work as expected', () => {
const img = new Image(100)
const audio = new Audio()
const option = new Option()

expect(img.width).toBe(100)
expect(audio).toBeInstanceOf(window.Audio)
expect(option).toBeInstanceOf(window.Option)
})

it('defined on self/window are defined on global', () => {
Expand Down

0 comments on commit 95ded47

Please sign in to comment.