MCPcopy Create free account
hub / github.com/vuejs/test-utils / createDOMEvent

Function createDOMEvent

src/createDomEvent.ts:147–178  ·  view source on GitHub ↗
(
  eventString: DomEventNameWithModifier | string,
  options?: TriggerOptions
)

Source from the content-addressed store, hash-verified

145}
146
147function createDOMEvent(
148 eventString: DomEventNameWithModifier | string,
149 options?: TriggerOptions
150) {
151 // split eventString like `keydown.ctrl.shift` into `keydown` and array of modifiers
152 const [eventType, ...modifiers] = eventString.split('.')
153
154 const eventParams: EventParams = {
155 eventType: eventType as DomEventName,
156 modifiers: modifiers as KeyName[],
157 options
158 }
159 const event: Event & TriggerOptions = createEvent(eventParams)
160 const eventPrototype = Object.getPrototypeOf(event)
161
162 // attach custom options to the event, like `relatedTarget` and so on.
163 if (options) {
164 Object.keys(options).forEach(key => {
165 const propertyDescriptor = Object.getOwnPropertyDescriptor(
166 eventPrototype,
167 key
168 )
169 const canSetProperty = !(
170 propertyDescriptor && propertyDescriptor.set === undefined
171 )
172 if (canSetProperty) {
173 event[key] = options[key]
174 }
175 })
176 }
177 return event
178}
179
180export {
181 TriggerOptions,

Callers 1

triggerFunction · 0.90

Calls 1

createEventFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…