TestObserver<T> class
Test utilities for zuraffa.
These utilities help write reliable, non-flaky tests by providing proper synchronization instead of arbitrary delays. A test observer that collects results and provides completion futures.
Use this instead of arbitrary Future.delayed in tests.
Example
test('GetUserUseCase returns user on success', () async {
final observer = TestObserver<User>();
getUserUseCase.listen('user-123', observer: observer);
// Wait for completion with timeout
final results = await observer.waitForCompletion();
expect(results, hasLength(1));
expect(results.first.name, equals('John'));
});
Constructors
Properties
-
failures
→ List<
AppFailure> -
All failures received
no setter
- firstFailure → AppFailure?
-
The first failure, if any
no setter
- hasFailures → bool
-
Whether any failures were received
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDone → bool
-
Whether the stream has completed
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
values
→ List<
T> -
All successful values received
no setter
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onData(
T data) → void -
Called when a new value is emitted.
override
-
onDone(
) → void -
Called when the stream completes.
override
-
onError(
AppFailure failure) → void -
Called when an error occurs.
override
-
reset(
) → void - Reset the observer for reuse.
-
toString(
) → String -
A string representation of this object.
inherited
-
waitForCompletion(
{Duration timeout = const Duration(seconds: 5)}) → Future< List< T> > - Wait for the stream to complete.
-
waitForFailure(
{Duration timeout = const Duration(seconds: 5)}) → Future< AppFailure> - Wait for any failure.
-
waitForValues(
int count, {Duration timeout = const Duration(seconds: 5)}) → Future< List< T> > - Wait for a specific number of values.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited