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

Function trigger

src/baseWrapper.ts:372–394  ·  view source on GitHub ↗
(eventString: string, options?: TriggerOptions)

Source from the content-addressed store, hash-verified

370 ): Promise<void>
371 async trigger(eventString: string, options?: TriggerOptions): Promise<void>
372 async trigger(eventString: string, options?: TriggerOptions) {
373 if (options && options['target']) {
374 throw Error(
375 `[vue-test-utils]: you cannot set the target value of an event. See the notes section ` +
376 `of the docs for more details—` +
377 `https://vue-test-utils.vuejs.org/api/wrapper/trigger.html`
378 )
379 }
380
381 if (this.element && !this.isDisabled()) {
382 const event = createDOMEvent(eventString, options)
383 // see https://github.com/vuejs/test-utils/issues/1854
384 // fakeTimers provoke an issue as Date.now() always return the same value
385 // and Vue relies on it to determine if the handler should be invoked
386 // see https://github.com/vuejs/core/blob/5ee40532a63e0b792e0c1eccf3cf68546a4e23e9/packages/runtime-dom/src/modules/events.ts#L100-L104
387 // we workaround this issue by manually setting _vts to Date.now() + 1
388 // thus making sure the event handler is invoked
389 event._vts = Date.now() + 1
390 this.element.dispatchEvent(event)
391 }
392
393 return nextTick()
394 }
395}

Callers

nothing calls this directly

Calls 1

createDOMEventFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…