* Helper to create a mock KeyboardEvent
(
key: string,
options: {
ctrlKey?: boolean
shiftKey?: boolean
altKey?: boolean
metaKey?: boolean
code?: string
} = {},
)
| 10 | * Helper to create a mock KeyboardEvent |
| 11 | */ |
| 12 | function createKeyboardEvent( |
| 13 | key: string, |
| 14 | options: { |
| 15 | ctrlKey?: boolean |
| 16 | shiftKey?: boolean |
| 17 | altKey?: boolean |
| 18 | metaKey?: boolean |
| 19 | code?: string |
| 20 | } = {}, |
| 21 | ): KeyboardEvent { |
| 22 | // Auto-generate code for letters and digits if not provided |
| 23 | let code = options.code |
| 24 | if (code === undefined) { |
| 25 | if (key.length === 1 && /^[a-zA-Z]$/.test(key)) { |
| 26 | code = `Key${key.toUpperCase()}` |
| 27 | } else if (key.length === 1 && /^[0-9]$/.test(key)) { |
| 28 | code = `Digit${key}` |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | return { |
| 33 | key, |
| 34 | code, |
| 35 | ctrlKey: options.ctrlKey ?? false, |
| 36 | shiftKey: options.shiftKey ?? false, |
| 37 | altKey: options.altKey ?? false, |
| 38 | metaKey: options.metaKey ?? false, |
| 39 | preventDefault: vi.fn(), |
| 40 | stopPropagation: vi.fn(), |
| 41 | } as unknown as KeyboardEvent |
| 42 | } |
| 43 | |
| 44 | describe('matchesKeyboardEvent', () => { |
| 45 | describe('single key matching', () => { |
no outgoing calls
no test coverage detected
searching dependent graphs…