


























@@ -290,6 +290,14 @@ function expectRecoverableRetryState(
290290expect(runSpy).toHaveBeenCalledTimes(expectedRunCalls);
291291}
292292293+function latestMockCall(mock: { mock: { calls: unknown[][] } }, label: string): unknown[] {
294+const call = mock.mock.calls[mock.mock.calls.length - 1];
295+if (!call) {
296+throw new Error(`expected ${label} call`);
297+}
298+return call;
299+}
300+293301async function monitorWithAutoAbort(opts: Omit<MonitorTelegramOpts, "abortSignal"> = {}) {
294302const abort = new AbortController();
295303mockRunOnceAndAbort(abort);
@@ -449,8 +457,8 @@ describe("monitorTelegramProvider (grammY)", () => {
449457sink?: { concurrency?: number };
450458runner?: { silent?: boolean; maxRetryTime?: number; retryInterval?: string };
451459};
452-const runCall = runSpy.mock.calls.at(-1) as unknown as [unknown, RunOptions] | undefined;
453-const runOptions = runCall?.[1];
460+const runCall = latestMockCall(runSpy, "run") as [unknown, RunOptions];
461+const runOptions = runCall[1];
454462expect(runOptions?.sink?.concurrency).toBe(3);
455463expect(runOptions?.runner?.silent).toBe(true);
456464expect(runOptions?.runner?.maxRetryTime).toBe(60 * 60 * 1000);
@@ -847,10 +855,10 @@ describe("monitorTelegramProvider (grammY)", () => {
847855},
848856});
849857850-const webhookCall = startTelegramWebhookSpy.mock.calls.at(-1) as
851-| [{ host?: string; setStatus?: unknown }]
852- | undefined;
853-const webhookOptions = webhookCall?.[0];
858+const webhookCall = latestMockCall(startTelegramWebhookSpy, "startTelegramWebhook") as [
859+{ host?: string; setStatus?: unknown },
860+];
861+const webhookOptions = webhookCall[0];
854862expect(webhookOptions?.host).toBe("0.0.0.0");
855863expect(webhookOptions?.setStatus).toBe(setStatus);
856864expect(runSpy).not.toHaveBeenCalled();
@@ -1018,10 +1026,10 @@ describe("monitorTelegramProvider (grammY)", () => {
10181026},
10191027});
102010281021-const webhookCall = startTelegramWebhookSpy.mock.calls.at(-1) as
1022-| [{ secret?: string }]
1023- | undefined;
1024-expect(webhookCall?.[0]?.secret).toBe("secret-from-config");
1029+const webhookCall = latestMockCall(startTelegramWebhookSpy, "startTelegramWebhook") as [
1030+{ secret?: string },
1031+];
1032+expect(webhookCall[0].secret).toBe("secret-from-config");
10251033expect(runSpy).not.toHaveBeenCalled();
10261034});
10271035});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。