describeMismatch method

  1. @override
Description describeMismatch(
  1. Object? item,
  2. Description mismatchDescription,
  3. Map matchState,
  4. bool verbose,
)
override

Builds a textual description of a specific mismatch.

item is the value that was tested by matches; matchState is the Map that was passed to and supplemented by matches with additional information about the mismatch, and mismatchDescription is the Description that is being built to describe the mismatch.

A few matchers make use of the verbose flag to provide detailed information that is not typically included but can be of help in diagnosing failures, such as stack traces.

Implementation

@override
Description describeMismatch(Object? item, Description mismatchDescription,
    Map matchState, bool verbose) {
  if (matchState['custom.exception'] != null) {
    mismatchDescription
        .add('threw ')
        .addDescriptionOf(matchState['custom.exception'])
        .add('\n')
        .add(matchState['custom.stack'].toString());
    return mismatchDescription;
  }

  mismatchDescription
      .add('has ')
      .add(_featureName)
      .add(' with value ')
      .addDescriptionOf(matchState['custom.feature']);
  var innerDescription = StringDescription();

  _matcher.describeMismatch(matchState['custom.feature'], innerDescription,
      matchState['state'] as Map, verbose);

  if (innerDescription.length > 0) {
    mismatchDescription.add(' which ').add(innerDescription.toString());
  }
  return mismatchDescription;
}