Personal Telegram developer console for GitHub
test: reproduce Cloudflare fetch receiver failure
davoodmehraban89 committed
Oct 3, 2026 at 00:36 UTC
99cf3468f820eb06390b7001c1d1eb5e5fb4ebbd
1 file changed
+24
test/telegram.test.js
+24
@@ -38,3 +38,27 @@ test('TelegramClient rejects Telegram ok:false responses even with HTTP 200', as
38
/message is not modified/i
39
);
40
});
41
+
42
+test('TelegramClient invokes the default fetch without a TelegramClient receiver', async () => {
43
+ const originalFetch = globalThis.fetch;
44
+ let observedThis;
45
+
46
+ globalThis.fetch = async function () {
47
+ observedThis = this;
48
+ if (this instanceof TelegramClient) {
49
+ throw new TypeError('Illegal invocation: function called with incorrect this reference');
50
+ }
51
+ return new Response(JSON.stringify({ ok: true, result: { message_id: 1 } }), {
52
+ status: 200,
53
+ headers: { 'content-type': 'application/json' }
54
+ });
55
+ };
56
+
57
+ try {
58
+ const client = new TelegramClient('token');
59
+ await client.sendMessage(1, 'hello');
60
+ assert.notEqual(observedThis, client);
61
+ } finally {
62
+ globalThis.fetch = originalFetch;
63
+ }
64
+});