Skip to content

Testing with Test Harness

createTestHarness(actor) instruments an actor, builds its graph, and records every state visit, transition, and effect.

import { createTestHarness } from "@mantaq/test";
const harness = createTestHarness(createCheckoutActor());

Use harness.send() instead of actor.send(). All sends are recorded.

harness.send(submitBasicInfo.create());
harness.send(submitShipping.create());
harness.send(submitPayment.create());
harness.send(paymentOk.create());
harness.assertStateVisited("basicInfo");
harness.assertStateVisited("success");
harness.assertAllStatesVisited();
  • assertStateVisited(id) / assertStateNeverVisited(id)
  • assertTransitionVisited(from, eventId) / assertTransitionNeverVisited(from, eventId)
  • assertEffectRan(id) / assertEffectNeverRan(id)
  • assertAllStatesVisited() / assertAllTransitionsVisited()
  • assertContextNever(predicate) fails if predicate matches current context

Non-throwing, return booleans:

harness.wasStateVisited("payment");
harness.wasTransitionVisited("payment", "submitPayment");
const report = harness.coverage();
// report.percent.states — 0–100
// report.percent.transitions — 0–100
// report.states.uncovered — string[]
// report.transitions.uncovered — Array<{ from, event }>

Use report.percent to gate CI. Use uncovered to find missing paths.

harness.reset() clears history between test cases.