TestAsyncUtils class Null safety

Utility class for all the async APIs in the flutter_test library.

This class provides checking for asynchronous APIs, allowing the library to verify that all the asynchronous APIs are properly awaited before calling another.

For example, it prevents this kind of code:

tester.pump(); // forgot to call "await"!
tester.pump();

...by detecting, in the second call to pump, that it should actually be:

await tester.pump();
await tester.pump();

It does this while still allowing nested calls, e.g. so that you can call expect from inside callbacks.

You can use this in your own test functions, if you have some asynchronous functions that must be used with "await". Wrap the contents of the function in a call to TestAsyncUtils.guard(), as follows:

Future<void> myTestFunction() => TestAsyncUtils.guard(() async {
  // ...
});

Properties

hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() String
A string representation of this object. [...]
inherited

Operators

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

Static Methods

guard<T>(Future<T> body()) Future<T>
Calls the given callback in a new async scope. The callback argument is the asynchronous body of the calling method. The calling method is said to be "guarded". Nested calls to guarded methods from within the body of this one are fine, but calls to other guarded methods from outside the body of this one before this one has finished will throw an exception. [...]
guardSync() → void
Verifies that there are no guarded methods currently pending (see guard). [...]
verifyAllScopesClosed() → void
Verifies that there are no guarded methods currently pending (see guard). [...]