diff --git a/packages/happy-dom/src/event/Event.ts b/packages/happy-dom/src/event/Event.ts index 8b0634ded..c039f9b68 100644 --- a/packages/happy-dom/src/event/Event.ts +++ b/packages/happy-dom/src/event/Event.ts @@ -12,9 +12,9 @@ import IDocument from '../nodes/document/IDocument.js'; * Event. */ export default class Event { - public composed = false; - public bubbles = false; - public cancelable = false; + public composed: boolean; + public bubbles: boolean; + public cancelable: boolean; public defaultPrevented = false; public eventPhase: EventPhaseEnum = EventPhaseEnum.none; public _immediatePropagationStopped = false; @@ -22,7 +22,7 @@ export default class Event { public _target: IEventTarget = null; public _currentTarget: IEventTarget = null; public timeStamp: number = performance.now(); - public type: string = null; + public type: string; public _isInPassiveEventListener = false; public NONE = EventPhaseEnum.none; public CAPTURING_PHASE = EventPhaseEnum.capturing; @@ -35,14 +35,12 @@ export default class Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IEventInit = null) { + constructor(type: string, eventInit: IEventInit | null = null) { this.type = type; - if (eventInit) { - this.bubbles = eventInit.bubbles || false; - this.cancelable = eventInit.cancelable || false; - this.composed = eventInit.composed || false; - } + this.bubbles = eventInit?.bubbles ?? false; + this.cancelable = eventInit?.cancelable ?? false; + this.composed = eventInit?.composed ?? false; } /** diff --git a/packages/happy-dom/src/event/UIEvent.ts b/packages/happy-dom/src/event/UIEvent.ts index 6e874aa3b..1fc859f16 100644 --- a/packages/happy-dom/src/event/UIEvent.ts +++ b/packages/happy-dom/src/event/UIEvent.ts @@ -10,12 +10,12 @@ export default class UIEvent extends Event { public static CAPTURING_PHASE = 1; public static AT_TARGET = 2; public static BUBBLING_PHASE = 3; - public readonly detail: number = 0; + public readonly detail: number; public readonly layerX: number = 0; public readonly layerY: number = 0; public readonly pageX: number = 0; public readonly pageY: number = 0; - public readonly view: IWindow = null; + public readonly view: IWindow | null; /** * Constructor. @@ -23,12 +23,10 @@ export default class UIEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IUIEventInit = null) { + constructor(type: string, eventInit: IUIEventInit | null = null) { super(type, eventInit); - if (eventInit) { - this.detail = eventInit.detail !== undefined ? eventInit.detail : 0; - this.view = eventInit.view || null; - } + this.detail = eventInit?.detail ?? 0; + this.view = eventInit?.view ?? null; } } diff --git a/packages/happy-dom/src/event/events/AnimationEvent.ts b/packages/happy-dom/src/event/events/AnimationEvent.ts index 771dc1fd1..669e26638 100644 --- a/packages/happy-dom/src/event/events/AnimationEvent.ts +++ b/packages/happy-dom/src/event/events/AnimationEvent.ts @@ -5,9 +5,9 @@ import IAnimationEventInit from './IAnimationEventInit.js'; * */ export default class AnimationEvent extends Event { - public animationName = ''; - public elapsedTime = 0; - public pseudoElement = ''; + public readonly animationName: string; + public readonly elapsedTime: number; + public readonly pseudoElement: string; /** * Constructor. @@ -15,10 +15,11 @@ export default class AnimationEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit?: IAnimationEventInit) { + constructor(type: string, eventInit: IAnimationEventInit | null = null) { super(type, eventInit); - this.animationName = eventInit?.animationName || ''; - this.elapsedTime = eventInit?.elapsedTime || 0; - this.pseudoElement = eventInit?.pseudoElement || ''; + + this.animationName = eventInit?.animationName ?? ''; + this.elapsedTime = eventInit?.elapsedTime ?? 0; + this.pseudoElement = eventInit?.pseudoElement ?? ''; } } diff --git a/packages/happy-dom/src/event/events/CustomEvent.ts b/packages/happy-dom/src/event/events/CustomEvent.ts index 91fc93be2..0393d9709 100644 --- a/packages/happy-dom/src/event/events/CustomEvent.ts +++ b/packages/happy-dom/src/event/events/CustomEvent.ts @@ -5,7 +5,8 @@ import ICustomEventInit from './ICustomEventInit.js'; * */ export default class CustomEvent extends Event { - public detail: object = null; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public detail: any; /** * Constructor. @@ -13,12 +14,10 @@ export default class CustomEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: ICustomEventInit = null) { + constructor(type: string, eventInit: ICustomEventInit | null = null) { super(type, eventInit); - if (eventInit) { - this.detail = eventInit.detail !== undefined ? eventInit.detail : null; - } + this.detail = eventInit?.detail ?? null; } /** diff --git a/packages/happy-dom/src/event/events/ErrorEvent.ts b/packages/happy-dom/src/event/events/ErrorEvent.ts index e06b6e2ba..1bd1725c5 100644 --- a/packages/happy-dom/src/event/events/ErrorEvent.ts +++ b/packages/happy-dom/src/event/events/ErrorEvent.ts @@ -5,11 +5,11 @@ import IErrorEventInit from './IErrorEventInit.js'; * */ export default class ErrorEvent extends UIEvent { - public readonly message: string = ''; - public readonly filename: string = ''; - public readonly lineno: number = 0; - public readonly colno: number = 0; - public readonly error: Error | null = null; + public readonly message: string; + public readonly filename: string; + public readonly lineno: number; + public readonly colno: number; + public readonly error: Error | null; /** * Constructor. @@ -17,15 +17,13 @@ export default class ErrorEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IErrorEventInit = null) { + constructor(type: string, eventInit: IErrorEventInit | null = null) { super(type, eventInit); - if (eventInit) { - this.message = eventInit.message || ''; - this.filename = eventInit.filename || ''; - this.lineno = eventInit.lineno !== undefined ? eventInit.lineno : 0; - this.colno = eventInit.colno !== undefined ? eventInit.colno : 0; - this.error = eventInit.error || null; - } + this.message = eventInit?.message ?? ''; + this.filename = eventInit?.filename ?? ''; + this.lineno = eventInit?.lineno ?? 0; + this.colno = eventInit?.colno ?? 0; + this.error = eventInit?.error ?? null; } } diff --git a/packages/happy-dom/src/event/events/FocusEvent.ts b/packages/happy-dom/src/event/events/FocusEvent.ts index 5aef7647a..3a6493050 100644 --- a/packages/happy-dom/src/event/events/FocusEvent.ts +++ b/packages/happy-dom/src/event/events/FocusEvent.ts @@ -6,7 +6,7 @@ import IFocusEventInit from './IFocusEventInit.js'; * */ export default class FocusEvent extends UIEvent { - public readonly relatedTarget: EventTarget = null; + public readonly relatedTarget: EventTarget | null; /** * Constructor. @@ -14,11 +14,9 @@ export default class FocusEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IFocusEventInit = null) { + constructor(type: string, eventInit: IFocusEventInit | null = null) { super(type, eventInit); - if (eventInit) { - this.relatedTarget = eventInit.relatedTarget || null; - } + this.relatedTarget = eventInit?.relatedTarget ?? null; } } diff --git a/packages/happy-dom/src/event/events/IPointerEventInit.ts b/packages/happy-dom/src/event/events/IPointerEventInit.ts index 1ec9a1684..145da4f19 100644 --- a/packages/happy-dom/src/event/events/IPointerEventInit.ts +++ b/packages/happy-dom/src/event/events/IPointerEventInit.ts @@ -1,4 +1,5 @@ import IMouseEventInit from './IMouseEventInit.js'; +import PointerEvent from './PointerEvent.js'; export default interface IPointerEventInit extends IMouseEventInit { pointerId?: number; @@ -9,6 +10,10 @@ export default interface IPointerEventInit extends IMouseEventInit { tiltX?: number; tiltY?: number; twist?: number; + altitudeAngle?: number; + azimuthAngle?: number; pointerType?: string; isPrimary?: boolean; + coalescedEvents?: PointerEvent[]; + predictedEvents?: PointerEvent[]; } diff --git a/packages/happy-dom/src/event/events/IStorageEventInit.ts b/packages/happy-dom/src/event/events/IStorageEventInit.ts index c7575f792..f0228cc94 100644 --- a/packages/happy-dom/src/event/events/IStorageEventInit.ts +++ b/packages/happy-dom/src/event/events/IStorageEventInit.ts @@ -3,7 +3,8 @@ import Storage from '../../storage/Storage.js'; export default interface IStorageEventInit extends IEventInit { key?: string; - newValue?: string; oldValue?: string; + newValue?: string; + url?: string; storageArea?: Storage; } diff --git a/packages/happy-dom/src/event/events/InputEvent.ts b/packages/happy-dom/src/event/events/InputEvent.ts index a906d4243..01c06d501 100644 --- a/packages/happy-dom/src/event/events/InputEvent.ts +++ b/packages/happy-dom/src/event/events/InputEvent.ts @@ -6,10 +6,10 @@ import IInputEventInit from './IInputEventInit.js'; * */ export default class InputEvent extends UIEvent { - public readonly data: string = ''; - public readonly dataTransfer: DataTransfer = null; - public readonly inputType: string = ''; - public readonly isComposing: boolean = false; + public readonly data: string; + public readonly dataTransfer: DataTransfer; + public readonly inputType: string; + public readonly isComposing: boolean; /** * Constructor. @@ -17,14 +17,12 @@ export default class InputEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IInputEventInit = null) { + constructor(type: string, eventInit: IInputEventInit | null = null) { super(type, eventInit); - if (eventInit) { - this.data = eventInit.data || ''; - this.dataTransfer = eventInit.dataTransfer || null; - this.inputType = eventInit.inputType || ''; - this.isComposing = eventInit.isComposing || false; - } + this.data = eventInit?.data ?? ''; + this.dataTransfer = eventInit?.dataTransfer ?? null; + this.inputType = eventInit?.inputType ?? ''; + this.isComposing = eventInit?.isComposing ?? false; } } diff --git a/packages/happy-dom/src/event/events/KeyboardEvent.ts b/packages/happy-dom/src/event/events/KeyboardEvent.ts index 6ff36a762..632c60f1a 100644 --- a/packages/happy-dom/src/event/events/KeyboardEvent.ts +++ b/packages/happy-dom/src/event/events/KeyboardEvent.ts @@ -9,15 +9,15 @@ export default class KeyboardEvent extends UIEvent { public static DOM_KEY_LOCATION_LEFT = 1; public static DOM_KEY_LOCATION_RIGHT = 2; public static DOM_KEY_LOCATION_NUMPAD = 3; - public readonly altKey: boolean = false; - public readonly code: string = ''; - public readonly ctrlKey: boolean = false; - public readonly isComposing: boolean = false; - public readonly key: string = ''; - public readonly location: number = 0; - public readonly metaKey: boolean = false; - public readonly repeat: boolean = false; - public readonly shiftKey: boolean = false; + public readonly altKey: boolean; + public readonly code: string; + public readonly ctrlKey: boolean; + public readonly isComposing: boolean; + public readonly key: string; + public readonly location: number; + public readonly metaKey: boolean; + public readonly repeat: boolean; + public readonly shiftKey: boolean; /** * Constructor. @@ -25,19 +25,17 @@ export default class KeyboardEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IKeyboardEventInit = null) { + constructor(type: string, eventInit: IKeyboardEventInit | null = null) { super(type, eventInit); - if (eventInit) { - this.altKey = eventInit.altKey || false; - this.code = eventInit.code || ''; - this.ctrlKey = eventInit.ctrlKey || false; - this.isComposing = eventInit.isComposing || false; - this.key = eventInit.key || ''; - this.location = eventInit.location !== undefined ? eventInit.location : 0; - this.metaKey = eventInit.metaKey || false; - this.repeat = eventInit.repeat || false; - this.shiftKey = eventInit.shiftKey || false; - } + this.altKey = eventInit?.altKey ?? false; + this.code = eventInit?.code ?? ''; + this.ctrlKey = eventInit?.ctrlKey ?? false; + this.isComposing = eventInit?.isComposing ?? false; + this.key = eventInit?.key ?? ''; + this.location = eventInit?.location ?? 0; + this.metaKey = eventInit?.metaKey ?? false; + this.repeat = eventInit?.repeat ?? false; + this.shiftKey = eventInit?.shiftKey ?? false; } } diff --git a/packages/happy-dom/src/event/events/MediaQueryListEvent.ts b/packages/happy-dom/src/event/events/MediaQueryListEvent.ts index 9125568e8..9d9f9e9eb 100644 --- a/packages/happy-dom/src/event/events/MediaQueryListEvent.ts +++ b/packages/happy-dom/src/event/events/MediaQueryListEvent.ts @@ -5,8 +5,8 @@ import IMediaQueryListInit from './IMediaQueryListInit.js'; * */ export default class MediaQueryListEvent extends Event { - public readonly matches: boolean = false; - public readonly media: string = ''; + public readonly matches: boolean; + public readonly media: string; /** * Constructor. @@ -14,12 +14,10 @@ export default class MediaQueryListEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IMediaQueryListInit = null) { + constructor(type: string, eventInit: IMediaQueryListInit | null = null) { super(type, eventInit); - if (eventInit) { - this.matches = eventInit.matches || false; - this.media = eventInit.media || ''; - } + this.matches = eventInit?.matches ?? false; + this.media = eventInit?.media ?? ''; } } diff --git a/packages/happy-dom/src/event/events/MessageEvent.ts b/packages/happy-dom/src/event/events/MessageEvent.ts index a0b2260cf..a2cd12f8e 100644 --- a/packages/happy-dom/src/event/events/MessageEvent.ts +++ b/packages/happy-dom/src/event/events/MessageEvent.ts @@ -9,11 +9,11 @@ import IMessageEventInit from './IMessageEventInit.js'; * @see https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent */ export default class MessageEvent extends Event { - public data?: unknown | null = null; - public origin?: string = ''; - public lastEventId?: string = ''; - public source?: IWindow | null = null; - public ports?: IMessagePort[] = []; + public readonly data: unknown | null; + public readonly origin: string; + public readonly lastEventId: string; + public readonly source: IWindow | null; + public readonly ports: IMessagePort[]; /** * Constructor. @@ -21,12 +21,13 @@ export default class MessageEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit?: IMessageEventInit) { + constructor(type: string, eventInit: IMessageEventInit | null = null) { super(type, eventInit); - this.data = eventInit?.data !== undefined ? eventInit.data : null; - this.origin = eventInit?.origin || ''; - this.lastEventId = eventInit?.lastEventId || ''; - this.source = eventInit?.source || null; - this.ports = eventInit?.ports || []; + + this.data = eventInit?.data ?? null; + this.origin = eventInit?.origin ?? ''; + this.lastEventId = eventInit?.lastEventId ?? ''; + this.source = eventInit?.source ?? null; + this.ports = eventInit?.ports ?? []; } } diff --git a/packages/happy-dom/src/event/events/MouseEvent.ts b/packages/happy-dom/src/event/events/MouseEvent.ts index 88dd6f04b..036a902a9 100644 --- a/packages/happy-dom/src/event/events/MouseEvent.ts +++ b/packages/happy-dom/src/event/events/MouseEvent.ts @@ -6,22 +6,22 @@ import IMouseEventInit from './IMouseEventInit.js'; * */ export default class MouseEvent extends UIEvent { - public readonly altKey: boolean = false; - public readonly button: number = 0; - public readonly buttons: number = 0; - public readonly clientX: number = 0; - public readonly clientY: number = 0; - public readonly ctrlKey: boolean = false; - public readonly metaKey: boolean = false; - public readonly movementX: number = 0; - public readonly movementY: number = 0; - public readonly offsetX: number = 0; - public readonly offsetY: number = 0; - public readonly region: string = ''; - public readonly relatedTarget: EventTarget = null; - public readonly screenX: number = 0; - public readonly screenY: number = 0; - public readonly shiftKey: boolean = false; + public readonly altKey: boolean; + public readonly button: number; + public readonly buttons: number; + public readonly clientX: number; + public readonly clientY: number; + public readonly ctrlKey: boolean; + public readonly metaKey: boolean; + public readonly movementX: number; + public readonly movementY: number; + public readonly offsetX: number; + public readonly offsetY: number; + public readonly region: string; + public readonly relatedTarget: EventTarget | null; + public readonly screenX: number; + public readonly screenY: number; + public readonly shiftKey: boolean; /** * Constructor. @@ -29,24 +29,22 @@ export default class MouseEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IMouseEventInit = null) { + constructor(type: string, eventInit: IMouseEventInit | null = null) { super(type, eventInit); - if (eventInit) { - this.altKey = eventInit.altKey || false; - this.button = eventInit.button !== undefined ? eventInit.button : 0; - this.buttons = eventInit.buttons !== undefined ? eventInit.buttons : 0; - this.clientX = eventInit.clientX !== undefined ? eventInit.clientX : 0; - this.clientY = eventInit.clientY !== undefined ? eventInit.clientY : 0; - this.ctrlKey = eventInit.ctrlKey || false; - this.metaKey = eventInit.metaKey || false; - this.movementX = eventInit.movementX || 0; - this.movementY = eventInit.movementY || 0; - this.region = eventInit.region || ''; - this.relatedTarget = eventInit.relatedTarget || null; - this.screenX = eventInit.screenX !== undefined ? eventInit.screenX : 0; - this.screenY = eventInit.screenY !== undefined ? eventInit.screenY : 0; - this.shiftKey = eventInit.shiftKey || false; - } + this.altKey = eventInit?.altKey ?? false; + this.button = eventInit?.button ?? 0; + this.buttons = eventInit?.buttons ?? 0; + this.clientX = eventInit?.clientX ?? 0; + this.clientY = eventInit?.clientY ?? 0; + this.ctrlKey = eventInit?.ctrlKey ?? false; + this.metaKey = eventInit?.metaKey ?? false; + this.movementX = eventInit?.movementX ?? 0; + this.movementY = eventInit?.movementY ?? 0; + this.region = eventInit?.region ?? ''; + this.relatedTarget = eventInit?.relatedTarget ?? null; + this.screenX = eventInit?.screenX ?? 0; + this.screenY = eventInit?.screenY ?? 0; + this.shiftKey = eventInit?.shiftKey ?? false; } } diff --git a/packages/happy-dom/src/event/events/PointerEvent.ts b/packages/happy-dom/src/event/events/PointerEvent.ts index bd0cc4ae0..32aa9d805 100644 --- a/packages/happy-dom/src/event/events/PointerEvent.ts +++ b/packages/happy-dom/src/event/events/PointerEvent.ts @@ -5,16 +5,20 @@ import IPointerEventInit from './IPointerEventInit.js'; * */ export default class PointerEvent extends MouseEvent { - public readonly pointerId: number = 0; - public readonly width: number = 0; - public readonly height: number = 0; - public readonly pressure: number = 0; - public readonly tangentialPressure: number = 0; - public readonly tiltX: number = 0; - public readonly tiltY: number = 0; - public readonly twist: number = 0; - public readonly pointerType: string = ''; - public readonly isPrimary: boolean = false; + public readonly pointerId: number; + public readonly width: number; + public readonly height: number; + public readonly pressure: number; + public readonly tangentialPressure: number; + public readonly tiltX: number; + public readonly tiltY: number; + public readonly twist: number; + public readonly altitudeAngle: number; + public readonly azimuthAngle: number; + public readonly pointerType: string; + public readonly isPrimary: boolean; + public readonly coalescedEvents: PointerEvent[]; + public readonly predictedEvents: PointerEvent[]; /** * Constructor. @@ -22,21 +26,26 @@ export default class PointerEvent extends MouseEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IPointerEventInit = null) { + constructor(type: string, eventInit: IPointerEventInit | null = null) { super(type, eventInit); - if (eventInit) { - this.pointerId = eventInit.pointerId !== undefined ? eventInit.pointerId : 0; - this.width = eventInit.width !== undefined ? eventInit.width : 0; - this.height = eventInit.height !== undefined ? eventInit.height : 0; - this.pressure = eventInit.pressure !== undefined ? eventInit.pressure : 0; - this.tangentialPressure = - eventInit.tangentialPressure !== undefined ? eventInit.tangentialPressure : 0; - this.tiltX = eventInit.tiltX !== undefined ? eventInit.tiltX : 0; - this.tiltY = eventInit.tiltY !== undefined ? eventInit.tiltY : 0; - this.twist = eventInit.twist !== undefined ? eventInit.twist : 0; - this.pointerType = eventInit.pointerType !== undefined ? eventInit.pointerType : ''; - this.isPrimary = eventInit.isPrimary || eventInit.isPrimary; - } + this.pointerId = eventInit?.pointerId ?? 0; + this.width = eventInit?.width ?? 1; + this.height = eventInit?.height ?? 1; + this.pressure = eventInit?.pressure ?? 0; + this.tangentialPressure = eventInit?.tangentialPressure ?? 0; + this.tiltX = eventInit?.tiltX ?? 0; + this.tiltY = eventInit?.tiltY ?? 0; + this.twist = eventInit?.twist ?? 0; + this.altitudeAngle = eventInit?.altitudeAngle ?? 0; + this.azimuthAngle = eventInit?.azimuthAngle ?? 0; + this.pointerType = eventInit?.pointerType ?? ''; + this.isPrimary = eventInit?.isPrimary ?? false; + this.coalescedEvents = eventInit?.coalescedEvents ?? []; + this.predictedEvents = eventInit?.predictedEvents ?? []; } + + public getCoalescedEvents = (): PointerEvent[] => this.coalescedEvents; + + public getPredictedEvents = (): PointerEvent[] => this.predictedEvents; } diff --git a/packages/happy-dom/src/event/events/ProgressEvent.ts b/packages/happy-dom/src/event/events/ProgressEvent.ts index 071e26f8d..1ed8dd6da 100644 --- a/packages/happy-dom/src/event/events/ProgressEvent.ts +++ b/packages/happy-dom/src/event/events/ProgressEvent.ts @@ -5,9 +5,9 @@ import IProgressEventInit from './IProgressEventInit.js'; * */ export default class ProgressEvent extends Event { - public readonly lengthComputable: boolean = false; - public readonly loaded: number = 0; - public readonly total: number = 0; + public readonly lengthComputable: boolean; + public readonly loaded: number; + public readonly total: number; /** * Constructor. @@ -15,13 +15,11 @@ export default class ProgressEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IProgressEventInit = null) { + constructor(type: string, eventInit: IProgressEventInit | null = null) { super(type); - if (eventInit) { - this.lengthComputable = eventInit.lengthComputable || false; - this.loaded = eventInit.loaded !== undefined ? eventInit.loaded : 0; - this.total = eventInit.total !== undefined ? eventInit.total : 0; - } + this.lengthComputable = eventInit?.lengthComputable ?? false; + this.loaded = eventInit?.loaded ?? 0; + this.total = eventInit?.total ?? 0; } } diff --git a/packages/happy-dom/src/event/events/StorageEvent.ts b/packages/happy-dom/src/event/events/StorageEvent.ts index a824409fe..24ea5498c 100644 --- a/packages/happy-dom/src/event/events/StorageEvent.ts +++ b/packages/happy-dom/src/event/events/StorageEvent.ts @@ -6,10 +6,11 @@ import Storage from '../../storage/Storage.js'; * */ export default class StorageEvent extends Event { - public readonly key: string = null; - public readonly newValue: string = null; - public readonly oldValue: string = null; - public readonly storageArea: Storage = null; + public readonly key: string | null; + public readonly oldValue: string | null; + public readonly newValue: string | null; + public readonly url: string; + public readonly storageArea: Storage | null; /** * Constructor. @@ -17,14 +18,13 @@ export default class StorageEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IStorageEventInit = null) { + constructor(type: string, eventInit: IStorageEventInit | null = null) { super(type); - if (eventInit) { - this.key = eventInit.key !== undefined ? eventInit.key : null; - this.newValue = eventInit.newValue !== undefined ? eventInit.newValue : null; - this.oldValue = eventInit.oldValue !== undefined ? eventInit.oldValue : null; - this.storageArea = eventInit.storageArea !== undefined ? eventInit.storageArea : null; - } + this.key = eventInit?.key ?? null; + this.oldValue = eventInit?.oldValue ?? null; + this.newValue = eventInit?.newValue ?? null; + this.url = eventInit?.url ?? ''; + this.storageArea = eventInit?.storageArea ?? null; } } diff --git a/packages/happy-dom/src/event/events/SubmitEvent.ts b/packages/happy-dom/src/event/events/SubmitEvent.ts index 773ace36e..864173cf1 100644 --- a/packages/happy-dom/src/event/events/SubmitEvent.ts +++ b/packages/happy-dom/src/event/events/SubmitEvent.ts @@ -6,7 +6,7 @@ import IHTMLElement from '../../nodes/html-element/IHTMLElement.js'; * An event triggered by form submit buttons. */ export default class SubmitEvent extends Event { - public readonly submitter: IHTMLElement; + public readonly submitter: IHTMLElement | null; /** * Constructor. @@ -14,9 +14,9 @@ export default class SubmitEvent extends Event { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: ISubmitEventInit = null) { + constructor(type: string, eventInit: ISubmitEventInit | null = null) { super(type, eventInit); - this.submitter = eventInit?.submitter || null; + this.submitter = eventInit?.submitter ?? null; } } diff --git a/packages/happy-dom/src/event/events/WheelEvent.ts b/packages/happy-dom/src/event/events/WheelEvent.ts index 3cfaa82ac..097d06007 100644 --- a/packages/happy-dom/src/event/events/WheelEvent.ts +++ b/packages/happy-dom/src/event/events/WheelEvent.ts @@ -8,10 +8,10 @@ export default class WheelEvent extends UIEvent { public static DOM_DELTA_PIXEL = 0; public static DOM_DELTA_LINE = 1; public static DOM_DELTA_PAGE = 2; - public readonly deltaX: number = 0; - public readonly deltaY: number = 0; - public readonly deltaZ: number = 0; - public readonly deltaMode: number = 0; + public readonly deltaX: number; + public readonly deltaY: number; + public readonly deltaZ: number; + public readonly deltaMode: number; /** * Constructor. @@ -19,14 +19,12 @@ export default class WheelEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IWheelEventInit = null) { + constructor(type: string, eventInit: IWheelEventInit | null = null) { super(type, eventInit); - if (eventInit) { - this.deltaX = eventInit.deltaX !== undefined ? eventInit.deltaX : 0; - this.deltaY = eventInit.deltaY !== undefined ? eventInit.deltaY : 0; - this.deltaZ = eventInit.deltaZ !== undefined ? eventInit.deltaZ : 0; - this.deltaMode = eventInit.deltaMode !== undefined ? eventInit.deltaMode : 0; - } + this.deltaX = eventInit?.deltaX ?? 0; + this.deltaY = eventInit?.deltaY ?? 0; + this.deltaZ = eventInit?.deltaZ ?? 0; + this.deltaMode = eventInit?.deltaMode ?? 0; } } diff --git a/packages/happy-dom/test/nodes/html-element/HTMLElement.test.ts b/packages/happy-dom/test/nodes/html-element/HTMLElement.test.ts index 054fa16c2..fb5194e66 100644 --- a/packages/happy-dom/test/nodes/html-element/HTMLElement.test.ts +++ b/packages/happy-dom/test/nodes/html-element/HTMLElement.test.ts @@ -394,6 +394,8 @@ describe('HTMLElement', () => { expect(((triggeredEvent)).composed).toBe(true); expect(((triggeredEvent)).target === element).toBe(true); expect(((triggeredEvent)).currentTarget === element).toBe(true); + expect(((triggeredEvent)).width).toBe(1); + expect(((triggeredEvent)).height).toBe(1); }); });