MCPcopy Index your code
hub / github.com/react/react / simulateEventDispatch

Function simulateEventDispatch

packages/internal-test-utils/ReactInternalTestUtils.js:348–379  ·  view source on GitHub ↗
(
  node: Node,
  eventType: string,
)

Source from the content-addressed store, hash-verified

346// between each event handler. This will allow discrete events to
347// flush between events across different event handlers.
348export async function simulateEventDispatch(
349 node: Node,
350 eventType: string,
351): Promise<void> {
352 // Ensure the node is in the document.
353 for (let current = node; current; current = current.parentNode) {
354 if (current === document) {
355 break;
356 } else if (current.parentNode == null) {
357 return;
358 }
359 }
360
361 const customEvent = new Event(eventType, {
362 bubbles: true,
363 });
364
365 Object.defineProperty(customEvent, 'target', {
366 // Override the target to the node on which we dispatched the event.
367 value: node,
368 });
369
370 const impl = Object.getOwnPropertySymbols(node)[0];
371 const oldDispatch = node[impl].dispatchEvent;
372 try {
373 node[impl].dispatchEvent = simulateBrowserEventDispatch;
374
375 await node.dispatchEvent(customEvent);
376 } finally {
377 node[impl].dispatchEvent = oldDispatch;
378 }
379}

Calls

no outgoing calls

Tested by

no test coverage detected