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: remove event related globals #11

Merged
merged 2 commits into from
Mar 19, 2024
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
4 changes: 0 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ class FixedJSDOMEnvironment extends JSDOMEnvironment {
this.global.TextEncoder = TextEncoder
this.global.ReadableStream = ReadableStream

this.global.EventTarget = EventTarget
this.global.Event = Event
this.global.MessageEvent = MessageEvent

this.global.Blob = Blob
this.global.Headers = Headers
this.global.FormData = FormData
Expand Down
61 changes: 0 additions & 61 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,64 +88,3 @@ test('exposes "structuredClone"', async () => {
expect(chunks).toEqual(['hello'])
})

test('exposes "EventTarget"', () => {
expect(globalThis).toHaveProperty('EventTarget')
expect(() => new EventTarget()).not.toThrow()

const target = new EventTarget()
const symbols = Object.getOwnPropertySymbols(target).map(
(symbol) => symbol.description,
)

// EventTarget must not be implemented by JSDOM.
expect(symbols).not.toContain('impl')

// In Node.js, EventTarget keeps events behind the kEvents symbol.
expect(symbols).toContain('kEvents')
})

test('exposes "Event"', () => {
expect(globalThis).toHaveProperty('Event')
expect(() => new Event('click')).not.toThrow()

const event = new Event('click')
const symbols = Object.getOwnPropertySymbols(event).map(
(symbol) => symbol.description,
)

// The "impl" symbol is added by JSDOM.
expect(symbols).not.toContain('impl')
// Node.js expects events to have the "type" symbol.
expect(symbols).toContain('type')

/**
* Perform a basic "isEvent()" check that Node.js has.
* @see https://github.com/nodejs/node/blob/3a456c6db802b5b25594d3a9d235d4989e9f7829/lib/internal/event_target.js#L96
*/
expect(event[symbols.find((description) => description === 'type')]).toBe(
'click',
)
})

test('exposes "MessageEvent"', () => {
expect(globalThis).toHaveProperty('MessageEvent')
expect(() => new MessageEvent('click')).not.toThrow()

const event = new MessageEvent('message')
const symbols = Object.getOwnPropertySymbols(event).map(
(symbol) => symbol.description,
)

// The "impl" symbol is added by JSDOM.
expect(symbols).not.toContain('impl')
// Node.js expects events to have the "type" symbol.
expect(symbols).toContain('type')

/**
* Perform a basic "isEvent()" check that Node.js has.
* @see https://github.com/nodejs/node/blob/3a456c6db802b5b25594d3a9d235d4989e9f7829/lib/internal/event_target.js#L96
*/
expect(event[symbols.find((description) => description === 'type')]).toBe(
'message',
)
})
Loading