




















@@ -44,17 +44,34 @@ let sendComponents: typeof import("../send.components.js");
44444545let lastDispatchCtx: Record<string, unknown> | undefined;
464647+type MockWithCalls = { mock: { calls: unknown[][] } };
48+49+function mockCall(mock: MockWithCalls, index: number, label: string): unknown[] {
50+const resolvedIndex = index < 0 ? mock.mock.calls.length + index : index;
51+const call = mock.mock.calls[resolvedIndex];
52+if (!call) {
53+throw new Error(`expected ${label} call`);
54+}
55+return call;
56+}
57+58+function mockCallArg(mock: MockWithCalls, index: number, label: string): unknown {
59+return mockCall(mock, index, label)[0];
60+}
61+4762function getLastRecordedCtx(): Record<string, unknown> | undefined {
48-const params = recordInboundSessionMock.mock.calls.at(-1)?.[0] as
49-| { ctx?: Record<string, unknown> }
50- | undefined;
63+const params = mockCallArg(recordInboundSessionMock, -1, "recordInboundSession") as {
64+ctx?: Record<string, unknown>;
65+};
5166return params?.ctx;
5267}
53685469function getLastPluginDispatchCtx(): Record<string, unknown> | undefined {
55-const params = dispatchPluginInteractiveHandlerMock.mock.calls.at(-1)?.[0] as
56-| { ctx?: Record<string, unknown> }
57-| undefined;
70+const params = mockCallArg(
71+dispatchPluginInteractiveHandlerMock,
72+-1,
73+"dispatchPluginInteractiveHandler",
74+) as { ctx?: Record<string, unknown> };
5875return params?.ctx;
5976}
6077@@ -65,14 +82,8 @@ function requireRecord(value: unknown, label: string): Record<string, unknown> {
6582return value as Record<string, unknown>;
6683}
678468-type MockWithCalls = { mock: { calls: unknown[][] } };
69-7085function firstMockCall(mock: MockWithCalls, label: string): unknown[] {
71-const call = mock.mock.calls.at(0);
72-if (!call) {
73-throw new Error(`expected ${label} call`);
74-}
75-return call;
86+return mockCall(mock, 0, label);
7687}
77887889function firstMockArg(mock: MockWithCalls, label: string) {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。