matches method Null safety
- dynamic item,
- 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) {
final 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) {
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;
}