AirTestHarness class

Testing utilities for Air Framework modules.

Provides a clean, isolated environment for testing modules, state flows, and inter-module communication.

Example:

void main() {
  testModule(
    module: CartModule(),
    initialState: {'cart.items': []},
    test: (module, harness) async {
      // Simulate adding an item
      harness.emitSignal('cart.add', {'productId': '123'});

      // Verify state changed
      expect(harness.getState('cart.items'), hasLength(1));
    },
  );
}

Test harness for Air modules

Available extensions

Constructors

AirTestHarness({Map<String, dynamic>? initialState})
Create a test harness with optional initial state

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

captureEvents<T extends ModuleEvent>() List<T>
Subscribe to events and return received events
captureSignals(String signalName) List
Subscribe to signals and return received data
emit<T extends ModuleEvent>(T event) → void
Emit a typed event
emitSignal(String signalName, [dynamic data]) → void
Emit a named signal
getEmittedEvents<T>() List<T>
Get all emitted events of a type
getEmittedSignals(String signalName) List
Get all emitted signals with a name
getState<T>(String key) → T?
Get current state value
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pump([Duration duration = const Duration(milliseconds: 10)]) Future<void>
Pump (process async events)
registerMock<T>(T mock, {String? moduleId}) → void
Register a mock service
setState<T>(String key, T value) → void
Set state value
setup() → void
Setup the test environment
stateOf(String key) StateMatcher

Available on AirTestHarness, provided by the AirTestHarnessMatchers extension

Get a state matcher for assertions
teardown() → void
Cleanup after test
toString() String
A string representation of this object.
inherited
waitFor(bool condition(), {Duration timeout = const Duration(seconds: 5), Duration pollInterval = const Duration(milliseconds: 50)}) Future<void>
Wait for a condition to be true (with timeout)
waitForState<T>(String key, T expectedValue, {Duration timeout = const Duration(seconds: 5)}) Future<void>
Wait for state to have a specific value

Operators

operator ==(Object other) bool
The equality operator.
inherited