FakeAsync class

A class that mocks out the passage of time within a Zone.

Test code can be passed as a callback to run, which causes it to be run in a Zone which fakes timer and microtask creation, such that they are run during calls to elapse which simulates the asynchronous passage of time.

The synchronous passage of time (as from blocking or expensive calls) can also be simulated using elapseBlocking.

Constructors

FakeAsync({DateTime? initialTime, bool includeTimerStackTrace = true})
Creates a FakeAsync.

Properties

elapsed Duration
The amount of fake time that's elapsed since this FakeAsync was created.
no setter
hashCode int
The hash code for this object.
no setterinherited
includeTimerStackTrace bool
Whether Timers created by this FakeAsync will include a creation stack trace in FakeAsync.pendingTimersDebugString.
final
microtaskCount int
The number of pending microtasks scheduled within a call to run or fakeAsync.
no setter
nonPeriodicTimerCount int
The number of active non-periodic timers created within a call to run or fakeAsync.
no setter
pendingTimers List<FakeTimer>
All the current pending timers.
no setter
pendingTimersDebugString List<String>
The debug strings for all the current pending timers.
no setter
periodicTimerCount int
The number of active periodic timers created within a call to run or fakeAsync.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

elapse(Duration duration) → void
Simulates the asynchronous passage of time.
elapseBlocking(Duration duration) → void
Simulates the synchronous passage of time, resulting from blocking or expensive calls.
flushMicrotasks() → void
Runs all pending microtasks scheduled within a call to run or fakeAsync until there are no more microtasks scheduled.
flushTimers({Duration timeout = const Duration(hours: 1), bool flushPeriodicTimers = true}) → void
Elapses time until there are no more active timers.
getClock(DateTime initialTime) Clock
Returns a fake Clock whose time can is elapsed by calls to elapse and elapseBlocking.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
run<T>(T callback(FakeAsync self)) → T
Runs callback in a Zone where all asynchrony is controlled by this.
toString() String
A string representation of this object.
inherited

Operators

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