expectAsync abstract method

Future<void> expectAsync(
  1. Iterable<String> clause(),
  2. FutureOr<Rejection?> predicate(
    1. T
    )
)

Expect that predicate will not result in a Rejection for the checked value.

The clause callback returns a description of what is checked which stands on its own. For instance the is equal to <1> in:

Expected: a int that:
  is equal to <1>

Description callbacks return an Iterable<String> where each element is a line in the output. Individual elements should not contain newlines. Utilities such as prefixFirst, postfixLast, and literal may be useful to format values which are potentially multiline.

The description of an expectation may never be shown to the user, so the callback may never be invoked. If all the conditions on a subject succeed, or if the failure detail for a failed softCheck is never read, the descriptions will be unused. String formatting for the descriptions should be performed in the callback, not ahead of time.

The context for a subject may hold a real "actual" value to test against, or it may have a placeholder within a call to describe. A context with a placeholder value will not invoke the callback to check expectations.

If both callbacks are invoked, the description callback will always be called strictly after the expectation callback is called.

Callbacks passed to a context should not throw.

Calls to expectAsync or nestAsync must not be performed by a condition callback passed to softCheck or describe. Use softCheckAsync or describeAsync for any condition which checks async expectations.

extension CustomChecks on Subject<CustomType> {
  Future<void> someAsyncExpectation() async {
    await context.expectAsync(() => ['meets this async expectation'],
        (actual) async {
      if (await _expectationIsMet(actual)) return null;
      return Rejection(which: ['does not meet this async expectation']);
    });
  }
}

Implementation

Future<void> expectAsync(Iterable<String> Function() clause,
    FutureOr<Rejection?> Function(T) predicate);