Overview
@artstesh/postboy-testing is a dedicated testing toolkit for applications built on top of @artstesh/postboy.
It gives you everything you need to write fast, readable, and isolated tests for event‑driven code — without setting up a real bus.
What it gives you
A fully compatible mock of
PostboyServicethat records every message and subscriptionDeclarative assertions for fired events, subscriptions, and message payloads
Async helpers to wait for events, callback results, or silence
A BDD‑style API (
given/then/waiter) that mirrors Arrange‑Act‑AssertTwo working modes — non‑strict (no registration required) and strict (explicit registry)
Automatic cleanup via
world.dispose()
How it fits into your tests
Every test revolves around a single entry point: PostboyWorld.
Internally PostboyWorld wires together a mock bus, a history log, a waiter service, and expressive APIs for preparation and verification. You don’t create mocks manually — you just instantiate the world and use it.
One place to arrange, act, and assert
PostboyWorld exposes five main properties that guide you through the test:
Property | Purpose |
|---|---|
| The mock bus — use it exactly like the real |
| Prepare mock behaviour (events, callbacks, executors) |
| Wait for async messages or verify silence |
| Verify what happened (fired, not fired, subscriptions) |
| Directly inspect recorded messages and subscriptions |
This design encourages a clear, three‑step rhythm in every test.
A minimal example
Imagine a service that fires an event after doing some work. A test with postboy-testing looks like this:
No spies, no manual mocks, no brittle expect on internal details — just a clean description of what the system communicates.
What’s next?
Quick Start — set up your first test in under two minutes
Core Concepts — understand
PostboyWorld, history, and the Arrange‑Act‑Assert flowRecipes — copy‑paste patterns for callbacks, executors, async testing, and more
The testing library is designed to grow with your knowledge: start with the Quick Start, keep the API Reference handy, and reach for Recipes when you face common testing scenarios.