( node: Node, eventType: string, )
| 346 | // between each event handler. This will allow discrete events to |
| 347 | // flush between events across different event handlers. |
| 348 | export 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 | } |
no outgoing calls
no test coverage detected