test: fix telegram fetch expectation

This commit is contained in:
Peter Steinberger
2026-01-08 07:51:58 +00:00
parent 34eb60e64e
commit 2450af26ec

View File

@@ -4,6 +4,7 @@ import path from "node:path";
import { beforeEach, describe, expect, it, vi } from "vitest"; import { beforeEach, describe, expect, it, vi } from "vitest";
import * as replyModule from "../auto-reply/reply.js"; import * as replyModule from "../auto-reply/reply.js";
import { createTelegramBot, getTelegramSequentialKey } from "./bot.js"; import { createTelegramBot, getTelegramSequentialKey } from "./bot.js";
import { resolveTelegramFetch } from "./fetch.js";
const { loadWebMedia } = vi.hoisted(() => ({ const { loadWebMedia } = vi.hoisted(() => ({
loadWebMedia: vi.fn(), loadWebMedia: vi.fn(),
@@ -140,12 +141,17 @@ describe("createTelegramBot", () => {
globalThis.fetch = fetchSpy; globalThis.fetch = fetchSpy;
try { try {
createTelegramBot({ token: "tok" }); createTelegramBot({ token: "tok" });
expect(botCtorSpy).toHaveBeenCalledWith( const fetchImpl = resolveTelegramFetch();
"tok", if (fetchImpl) {
expect.objectContaining({ expect(botCtorSpy).toHaveBeenCalledWith(
client: expect.objectContaining({ fetch: fetchSpy }), "tok",
}), expect.objectContaining({
); client: expect.objectContaining({ fetch: fetchSpy }),
}),
);
} else {
expect(botCtorSpy).toHaveBeenCalledWith("tok", undefined);
}
} finally { } finally {
globalThis.fetch = originalFetch; globalThis.fetch = originalFetch;
} }