TypeMatcher<T> class

A Matcher subclass that supports validating the Type of the target object.

expect(shouldBeDuration, new TypeMatcher<Duration>());

If you want to further validate attributes of the specified Type, use the having function.

void shouldThrowRangeError(int value) {
  throw new RangeError.range(value, 10, 20);
}

expect(
    () => shouldThrowRangeError(5),
    throwsA(const TypeMatcher<RangeError>()
        .having((e) => e.start, 'start', greaterThanOrEqualTo(10))
        .having((e) => e.end, 'end', lessThanOrEqualTo(20))));

Notice that you can chain multiple calls to having to verify multiple aspects of an object.

Note: All of the top-level isType matchers exposed by this package are instances of TypeMatcher, so you can use the having function without creating your own instance.

expect(
    () => shouldThrowRangeError(5),
    throwsA(isRangeError
        .having((e) => e.start, 'start', greaterThanOrEqualTo(10))
        .having((e) => e.end, 'end', lessThanOrEqualTo(20))));
Inheritance
Implementers

Constructors

TypeMatcher([@Deprecated('Provide a type argument to TypeMatcher and omit the name. This argument will be removed in the next release.') String name ])
const

Properties

hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

describe(Description description) Description
Builds a textual description of the matcher.
override
having(Object feature(T source), String description, Object matcher) TypeMatcher<T>
Returns a new TypeMatcher that validates the existing type as well as a specific feature of the object with the provided matcher. [...]
matches(Object item, Map matchState) bool
Does the matching of the actual vs expected values. [...]
override
describeMismatch(dynamic item, Description mismatchDescription, Map matchState, bool verbose) Description
Builds a textual description of a specific mismatch. [...]
inherited
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

Operators

operator ==(dynamic other) bool
The equality operator. [...]
inherited