Teact
Packages

@teactjs/testing

MockAdapter to simulate updates and assert sends, and renderBot to inspect component output — no Telegram network calls.

Test Teact bots without hitting Telegram. MockAdapter records sent messages and lets you simulate incoming updates; renderBot renders a component in isolation and returns its serialized output tree. Works with Vitest, Jest, or bun test.

bun add -D @teactjs/testing

Exports

ExportKindDescription
MockAdapterclassIn-memory adapter that records sends and simulates updates.
renderBotfunctionRender a component to an output tree with assertion helpers.
SentMessage, EditedMessagetypesRecorded message shapes.
RenderResulttypeReturn type of renderBot.

MockAdapter

Pass it to createBot as the adapter, then drive updates and assert on sent / edited:

import { MockAdapter } from "@teactjs/testing";
import { createBot } from "@teactjs/core";

const adapter = new MockAdapter();
const bot = createBot({ component: App, adapter, token: "test" });
await bot.start();

await adapter.simulateMessage("1", "1", "/start");   // (chatId, userId, text)
await adapter.simulateCallback("1", "1", "ok");       // (chatId, userId, data, messageId?)

adapter.getLastSent(); // most recent SentMessage | undefined
adapter.sent;          // SentMessage[]
adapter.edited;        // EditedMessage[]
adapter.reset();

renderBot

renderBot(Component, initialCtx?) renders a { ctx } component and returns the serialized tree plus helpers. rerender accepts a Partial<BotContext>:

import { renderBot } from "@teactjs/testing";

const result = renderBot(MyComponent);
result.output;                  // serialized OutputNode | null
result.findByType("tg-button"); // OutputNode[]
result.findText();              // concatenated text
result.rerender({ text: "/help" });
result.unmount();

See the Testing guide for full examples.

On this page