completes method

  1. @awaitNotRequired
Future<void> completes([
  1. AsyncCondition<T>? completionCondition
])

Expects that the Future completes to a value without throwing.

Fails if the future completes as an error.

Pass completionCondition to check expectations on the completion result.

The returned future will complete when the subject future has completed, and completionCondition has optionally been checked.

Implementation

@awaitNotRequired
Future<void> completes([AsyncCondition<T>? completionCondition]) {
  return context.nestAsync<T>(
    () => ['completes to a value'],
    addPredicate: (predicateNoun) => 'completes to $predicateNoun',
    (actual) async {
      try {
        return Extracted.value(await actual);
      } catch (e, st) {
        return Extracted.rejection(
          actual: ['a future that completes as an error'],
          which: [
            ...prefixFirst('threw ', postfixLast(' at:', literal(e))),
            ...indent(LineSplitter.split(st.toString())),
          ],
        );
      }
    },
    completionCondition,
  );
}