Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow accessing Audio, Option and private jsdom props on global #1443

Merged
merged 3 commits into from Jun 9, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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