matches method

  1. @override
bool matches(
  1. dynamic item,
  2. Map matchState
)
inherited

Does the matching of the actual vs expected values.

item is the actual value. matchState can be supplied and may be used to add details about the mismatch that are too costly to determine in describeMismatch.

Implementation

@override
bool matches(dynamic item, Map matchState) {
  final result = matchAsync(item);
  expect(
      result,
      anyOf([
        equals(null),
        const TypeMatcher<Future>(),
        const TypeMatcher<String>()
      ]),
      reason: 'matchAsync() may only return a String, a Future, or null.');

  if (result is Future) {
    final outstandingWork = TestHandle.current.markPending();
    result.then((realResult) {
      if (realResult != null) {
        fail(formatFailure(this, item, realResult as String));
      }
      outstandingWork.complete();
    });
  } else if (result is String) {
    matchState[this] = result;
    return false;
  }

  return true;
}