mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-19 05:50:47 +00:00
test(telegram): cancel real timer in media group tests to prevent double invocation
This commit is contained in:
committed by
Ayaan Zaidi
parent
81fe06c058
commit
1d145ff71d
@@ -1760,10 +1760,19 @@ describe("createTelegramBot", () => {
|
||||
await Promise.all([first, second]);
|
||||
expect(replySpy).not.toHaveBeenCalled();
|
||||
|
||||
const flushTimerCall = [...setTimeoutSpy.mock.calls]
|
||||
.toReversed()
|
||||
.find((call) => call[1] === TELEGRAM_TEST_TIMINGS.mediaGroupFlushMs);
|
||||
const flushTimer = flushTimerCall?.[0] as (() => unknown) | undefined;
|
||||
const flushTimerCallIndex = setTimeoutSpy.mock.calls.findLastIndex(
|
||||
(call) => call[1] === TELEGRAM_TEST_TIMINGS.mediaGroupFlushMs,
|
||||
);
|
||||
const flushTimer =
|
||||
flushTimerCallIndex >= 0
|
||||
? (setTimeoutSpy.mock.calls[flushTimerCallIndex]?.[0] as (() => unknown) | undefined)
|
||||
: undefined;
|
||||
// Cancel the real timer so it cannot fire a second time after we manually invoke it.
|
||||
if (flushTimerCallIndex >= 0) {
|
||||
clearTimeout(
|
||||
setTimeoutSpy.mock.results[flushTimerCallIndex]?.value as ReturnType<typeof setTimeout>,
|
||||
);
|
||||
}
|
||||
expect(flushTimer).toBeTypeOf("function");
|
||||
await flushTimer?.();
|
||||
|
||||
@@ -1939,10 +1948,19 @@ describe("createTelegramBot", () => {
|
||||
await Promise.all([first, second]);
|
||||
expect(replySpy).not.toHaveBeenCalled();
|
||||
|
||||
const flushTimerCall = [...setTimeoutSpy.mock.calls]
|
||||
.toReversed()
|
||||
.find((call) => call[1] === TELEGRAM_TEST_TIMINGS.mediaGroupFlushMs);
|
||||
const flushTimer = flushTimerCall?.[0] as (() => unknown) | undefined;
|
||||
const flushTimerCallIndex = setTimeoutSpy.mock.calls.findLastIndex(
|
||||
(call) => call[1] === TELEGRAM_TEST_TIMINGS.mediaGroupFlushMs,
|
||||
);
|
||||
const flushTimer =
|
||||
flushTimerCallIndex >= 0
|
||||
? (setTimeoutSpy.mock.calls[flushTimerCallIndex]?.[0] as (() => unknown) | undefined)
|
||||
: undefined;
|
||||
// Cancel the real timer so it cannot fire a second time after we manually invoke it.
|
||||
if (flushTimerCallIndex >= 0) {
|
||||
clearTimeout(
|
||||
setTimeoutSpy.mock.results[flushTimerCallIndex]?.value as ReturnType<typeof setTimeout>,
|
||||
);
|
||||
}
|
||||
expect(flushTimer).toBeTypeOf("function");
|
||||
await flushTimer?.();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user