Testing
@artstesh/postboy-testing (v3.4.x) is the BDD-style testing toolkit for applications built on the postboy message bus. Its core is PostboyServiceMock: a recording drop-in replacement for PostboyService. The mock captures every fired message, executed command, subscription, and callback result. Three services wrap the mock: given stubs bus behavior, then asserts recorded history, and waiter waits for asynchronous messages. All of them hang off a single test fixture, PostboyWorld.
Installation
Install the toolkit as a development dependency. Both peer dependencies must be present in the project.
Package | Role | Version |
|---|---|---|
| dev dependency | 3.4.x |
| peer |
|
| peer |
|
The toolkit is framework-agnostic and works with Jest, Vitest, Jasmine, or Karma.
The canonical flow
Every test follows the same five steps: create the world, stub with given, run the system under test with world.postboy, assert with then or await with waiter, dispose the world.
What the world gives you
Getter | Purpose |
|---|---|
| The recording mock bus. Inject it wherever the SUT expects a |
| Stub executors, callback responses, and pre-fired events. |
| Fluent assertions: |
| Promise-based waits: |
| Direct access to recorded messages, callback results, and subscription counts. |
| Low-level stream mocks for cases |
| Namespaced registrator for manual registration, required in strict mode. |
Pitfalls
Recording only happens through
world.postboy. A plainPostboyServicerecords nothing.world.dispose()must run after every test, and the world is not reusable afterwards.By default the world is non-strict: unknown message types are auto-registered. In strict mode every type must be registered first.
Next steps
Quick start: a complete jest test, end to end.
PostboyWorld: world anatomy, strict mode, dispose discipline, escape hatches.
Assertions: the
thenbuilders, message history, and the boolean verifier.Async waiters: the
waitForfamily and its options.Recipes: task-based patterns for common test scenarios.
API reference: full signatures.