A useful utility class for implementing other matchers through inheritance. Derived classes should call the base constructor with a feature name and description, and an instance matcher, and should implement the featureValueOf abstract method.

The feature description will typically describe the item and the feature, while the feature name will just name the feature. For example, we may have a Widget class where each Widget has a price; we could make a CustomMatcher that can make assertions about prices with:

class HasPrice extends CustomMatcher {
  const HasPrice(matcher) :
      super("Widget with price that is", "price", matcher);
  featureValueOf(actual) => actual.price;
}

and then use this for example like:

 expect(inventoryItem, new HasPrice(greaterThan(0)));
Inheritance

Constructors

CustomMatcher(String _featureDescription, String _featureName, matcher)

Properties

hashCode int

Get a hash code for this object.

read-only, inherited
runtimeType Type

A representation of the runtime type of the object.

read-only, inherited

Operators

operator ==(other) bool

The equality operator.

inherited

Methods

describe(Description description) Description

This builds a textual description of the matcher.

describeMismatch(item, Description mismatchDescription, Map matchState, bool verbose) Description

This 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 decribe 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.

featureValueOf(actual) → dynamic

Override this to extract the interesting feature.

matches(item, Map matchState) bool

This 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.

noSuchMethod(Invocation invocation) → dynamic

Invoked when a non-existent method or property is accessed.

inherited
toString() String

Returns a string representation of this object.

inherited