( event: TEvent, type: TAssertedDescriptor | readonly TAssertedDescriptor[] )
| 25 | * ``` |
| 26 | */ |
| 27 | export function assertEvent< |
| 28 | TEvent extends EventObject, |
| 29 | TAssertedDescriptor extends EventDescriptor<TEvent> |
| 30 | >( |
| 31 | event: TEvent, |
| 32 | type: TAssertedDescriptor | readonly TAssertedDescriptor[] |
| 33 | ): asserts event is ExtractEvent<TEvent, TAssertedDescriptor> { |
| 34 | const types = toArray(type); |
| 35 | |
| 36 | const matches = types.some((descriptor) => |
| 37 | matchesEventDescriptor(event.type, descriptor as string) |
| 38 | ); |
| 39 | |
| 40 | if (!matches) { |
| 41 | const typesText = |
| 42 | types.length === 1 |
| 43 | ? `type matching "${types[0]}"` |
| 44 | : `one of types matching "${types.join('", "')}"`; |
| 45 | throw new Error( |
| 46 | `Expected event ${JSON.stringify(event)} to have ${typesText}` |
| 47 | ); |
| 48 | } |
| 49 | } |
no test coverage detected