Skip to content
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
2 changes: 1 addition & 1 deletion packages/vitest/src/integrations/env/jsdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ function patchAddEventListener(window: DOMWindow) {
callback: EventListenerOrEventListenerObject | null,
options?: AddEventListenerOptions | boolean,
) {
if (typeof options === 'object' && options.signal != null) {
if (typeof options === 'object' && options?.signal != null) {
const { signal, ...otherOptions } = options
// - this happens because AbortSignal is provided by Node.js,
// but jsdom APIs require jsdom's AbortSignal, while Node APIs
Expand Down
14 changes: 14 additions & 0 deletions test/core/test/environments/jsdom.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,20 @@ test('can pass down the same abort signal many times without a warning', ({ onTe
}))
})

test('DOM APIs addEventListener allow null as third parameter', () => {
const element = document.createElement('div')
document.body.append(element)
const spy = vi.fn()

// eslint-disable-next-line ts/ban-ts-comment
// @ts-expect-error
element.addEventListener('click', spy, null)

element.click()

expect(spy).toHaveBeenCalledTimes(1)
})

test('atob and btoa are available', () => {
expect(atob('aGVsbG8gd29ybGQ=')).toBe('hello world')
expect(btoa('hello world')).toBe('aGVsbG8gd29ybGQ=')
Expand Down
Loading