MCPcopy
hub / github.com/statelyai/xstate / assertEvent

Function assertEvent

packages/core/src/assert.ts:27–49  ·  view source on GitHub ↗
(
  event: TEvent,
  type: TAssertedDescriptor | readonly TAssertedDescriptor[]
)

Source from the content-addressed store, hash-verified

25 * ```
26 */
27export 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}

Callers 3

assert.test.tsFile · 0.90

Calls 2

toArrayFunction · 0.90
matchesEventDescriptorFunction · 0.90

Tested by

no test coverage detected