Teact
Guides

Testing bots

MockAdapter to simulate updates and assert sends; renderBot for isolated component trees.

MockAdapter

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();

// positional args: (chatId, userId, text)
adapter.simulateMessage("1", "1", "/start");
adapter.simulateCallback("1", "1", "ok");

adapter.getLastSent();
adapter.sent;
adapter.edited;
adapter.reset();

renderBot

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

const result = renderBot(MyComponent);
result.output;
result.findByType("tg-button");
result.findText();
result.rerender({ text: "/help" });
result.unmount();

Use with Vitest or Jest. See @teactjs/testing.

On this page