* Minimal mock that satisfies the Closable interface used by the * reconnection utility. Each instance records every `addEventListener` * call and exposes helpers to fire those events.
()
| 9 | * call and exposes helpers to fire those events. |
| 10 | */ |
| 11 | function createMockSocket() { |
| 12 | const listeners: Record<string, Array<(...args: unknown[]) => void>> = {}; |
| 13 | const socket = { |
| 14 | addEventListener: vi.fn( |
| 15 | (event: string, handler: (...args: unknown[]) => void) => { |
| 16 | if (!listeners[event]) { |
| 17 | listeners[event] = []; |
| 18 | } |
| 19 | listeners[event].push(handler); |
| 20 | }, |
| 21 | ), |
| 22 | close: vi.fn(), |
| 23 | /** Fire all handlers registered for the given event type. */ |
| 24 | emit(event: string) { |
| 25 | for (const handler of listeners[event] ?? []) { |
| 26 | handler(); |
| 27 | } |
| 28 | }, |
| 29 | }; |
| 30 | return socket; |
| 31 | } |
| 32 | |
| 33 | const expectReconnectSchedule = ( |
| 34 | event: { reconnect: ReconnectSchedule; now: number }, |
no test coverage detected