Skip to content

Low-Level API

The low-level layer gives you direct access to the machinery underneath the high-level actors. Import it from the grammy-testing/low-level subpath.

When to use it

Use the low-level layer when you need to:

  • Inspect raw API payloadschats.outgoing.requests[n].payload
  • Simulate API errorsfailNext('sendMessage', { code: 403 })
  • Provide canned responsesrespondNext('getChat', { ... })
  • Build unusual update shapesnew GenericMockUpdate({ ... }).build()
  • Mock session or statemockSession({ count: 0 })
  • Test a composer or middleware in isolationprepareComposer, prepareMiddleware

Most tests don't need any of this — the high-level actors cover the common cases.

Subpath export

The low-level update builders are only available from the /low-level subpath:

ts
import { GenericMockUpdate, MessageMockUpdate } from 'grammy-testing/low-level';

Everything else (prepare functions, OutgoingRequests, mock* helpers) is available from the main entry point:

ts
import { prepareBot, OutgoingRequests, mockSession } from 'grammy-testing';

What's in this section

PageWhat it covers
Outgoing RequestsCapture store, typed accessors, error / response simulation
Session MockingmockSession, mockChatSession, mockState, mockContextField
Update BuildersRaw update construction for edge cases
Response MockingCanned responses via prepareBot options

Released under the MIT License.