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(item, Map matchState) {
  var result = matchAsync(item);
  expect(result,
      anyOf([equals(null), TypeMatcher<Future>(), TypeMatcher<String>()]),
      reason: 'matchAsync() may only return a String, a Future, or null.');

  if (result is Future) {
    Invoker.current.addOutstandingCallback();
    result.then((realResult) {
      if (realResult != null) {
        fail(formatFailure(this, item, realResult as String));
      }
      Invoker.current.removeOutstandingCallback();
    });
  } else if (result is String) {
    matchState[this] = result;
    return false;
  }

  return true;
}