Skip to content

Commit

Permalink
fix: remove event related globals (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesZoft committed Mar 19, 2024
1 parent 116db09 commit 89aabb4
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 65 deletions.
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',
)
})

0 comments on commit 89aabb4

Please sign in to comment.