* Helper to dispatch a keyboard event from a specific element. * Focuses the element first to set document.activeElement, then dispatches * on the element so listeners attached to it receive the event.
(
element: HTMLElement,
key: string,
options: {
eventType?: 'keydown' | 'keyup'
ctrlKey?: boolean
shiftKey?: boolean
altKey?: boolean
metaKey?: boolean
} = {},
)
| 24 | * on the element so listeners attached to it receive the event. |
| 25 | */ |
| 26 | function dispatchKeyFromElement( |
| 27 | element: HTMLElement, |
| 28 | key: string, |
| 29 | options: { |
| 30 | eventType?: 'keydown' | 'keyup' |
| 31 | ctrlKey?: boolean |
| 32 | shiftKey?: boolean |
| 33 | altKey?: boolean |
| 34 | metaKey?: boolean |
| 35 | } = {}, |
| 36 | ): KeyboardEvent { |
| 37 | // Focus the element so document.activeElement is set |
| 38 | element.focus() |
| 39 | |
| 40 | const eventType = options.eventType ?? 'keydown' |
| 41 | const event = new KeyboardEvent(eventType, { |
| 42 | key, |
| 43 | ctrlKey: options.ctrlKey ?? false, |
| 44 | shiftKey: options.shiftKey ?? false, |
| 45 | altKey: options.altKey ?? false, |
| 46 | metaKey: options.metaKey ?? false, |
| 47 | bubbles: true, |
| 48 | }) |
| 49 | element.dispatchEvent(event) |
| 50 | return event |
| 51 | } |
| 52 | |
| 53 | describe('SequenceManager', () => { |
| 54 | beforeEach(() => { |
no outgoing calls
no test coverage detected
searching dependent graphs…