CustomMatcher class
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 {
HasPrice(matcher) : super("Widget with price that is", "price", matcher);
featureValueOf(actual) => (actual as Widget).price;
}
and then use this for example like:
expect(inventoryItem, HasPrice(greaterThan(0)));
Constructors
- CustomMatcher(String _featureDescription, String _featureName, Object? valueOrMatcher)
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
describe(
Description description) → Description -
Builds a textual description of the matcher.
override
-
describeMismatch(
Object? item, Description mismatchDescription, Map matchState, bool verbose) → Description -
Builds a textual description of a specific mismatch.
override
-
featureValueOf(
dynamic actual) → Object? - Override this to extract the interesting feature.
-
matches(
Object? item, Map matchState) → bool -
Does the matching of the actual vs expected values.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited