ShardTester<T> class

A helper for testing Shard subclasses by capturing emissions, waiting for specific states, and asserting state sequences.

final shard = CounterShard();
final tester = ShardTester(shard);
addTearDown(tester.dispose);
addTearDown(shard.dispose);

shard.increment();
shard.increment();
await tester.expectStates([1, 2]);

ShardTester does not depend on flutter_test matchers; it raises ShardAssertionError / ShardTimeoutError which the surrounding test framework treats as failures.

Constructors

ShardTester(Shard<T> _shard)
Subscribes to shard and starts recording emissions.

Properties

hashCode int
The hash code for this object.
no setterinherited
hasStates bool
Whether at least one state has been recorded.
no setter
lastState → T?
The most recent recorded state, or null if none.
no setter
recordedStates List<T>
All states emitted since construction, in order.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shard Shard<T>
The shard being observed.
no setter

Methods

clear() → void
Empties recordedStates without unsubscribing.
dispose() Future<void>
Removes the listener and fails any pending waiters.
expectNoMoreStates({Duration window = const Duration(milliseconds: 100)}) Future<void>
Asserts no states are emitted within window.
expectStates(List<T> expected, {Duration timeout = const Duration(seconds: 1), bool exactMatch = false}) Future<void>
Asserts the recorded state sequence matches expected in order.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
waitFor(bool predicate(T state), {Duration timeout = const Duration(seconds: 1)}) Future<T>
Waits for a state that satisfies predicate and returns it.
waitForNext({Duration timeout = const Duration(seconds: 1)}) Future<T>
Waits for the next emission and returns it.

Operators

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

Static Methods

scope<S, R>(Shard<S> shard, Future<R> body(ShardTester<S> tester)) Future<R>
Creates a ShardTester around shard, runs body, and disposes the tester in a finally block. Returns whatever body returns.