MockShardObserver class

A ShardObserver that records all events for inspection in tests.

Because Shard.observer is a global static, prefer scope over manual install/uninstall to avoid cross-test pollution.

await MockShardObserver.scope((observer) async {
  final shard = MyShard();
  addTearDown(shard.dispose);
  shard.doSomething();
  expect(observer.changesFor(shard), hasLength(1));
});
Inheritance

Constructors

MockShardObserver()
Creates a fresh MockShardObserver with empty recordings.

Properties

hashCode int
The hash code for this object.
no setterinherited
recordedChanges List<ObservedChange>
All recorded change events, in order.
no setter
recordedErrors List<ObservedError>
All recorded error events, in order.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

changesFor<T>(Shard<T> shard) List<ObservedChange<T>>
Recorded changes whose shard is shard (identity comparison).
changesOfType<T>() List<ObservedChange<T>>
All recorded changes for any Shard<T> of the given state type.
clear() → void
Clears all recorded events.
errorsFor(Shard shard) List<ObservedError>
Recorded errors whose shard is shard (identity comparison).
errorsOfType<S extends Shard>() List<ObservedError>
All recorded errors whose shard is of runtime type S.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onChange<T>(Shard<T> shard, T previousState, T currentState) → void
Called whenever a Shard's state changes.
override
onError<T>(Shard<T> shard, Object error, StackTrace? stackTrace) → void
Called when an error is reported via Shard.addError.
override
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

scope<R>(Future<R> body(MockShardObserver observer)) Future<R>
Installs a fresh MockShardObserver as the global observer for the duration of body, then restores whatever observer was previously set (including null) in a finally block.