isInstanceOf<T> class
Returns a matcher that matches if an object is an instance
of type
(or a subtype).
As types are not first class objects in Dart we can only approximate this test by using a generic wrapper class.
For example, to test whether 'bar' is an instance of type 'Foo', we would write:
expect(bar, new isInstanceOf<Foo>());
To get better error message, supply a name when creating the Type wrapper; e.g.:
expect(bar, new isInstanceOf<Foo>('Foo'));
class isInstanceOf<T> extends BaseMatcher { final String _name; const isInstanceOf([name = 'specified type']) : this._name = name; bool matches(obj, MatchState matchState) => obj is T; // The description here is lame :-( Description describe(Description description) => description.add('an instance of ${_name}'); }
Extends
BaseMatcher > isInstanceOf<T>
Constructors
const isInstanceOf([name = 'specified type']) #
const isInstanceOf([name = 'specified type']) : this._name = name;
Methods
Description describe(Description description) #
Creates a textual description of a matcher,
by appending to mismatchDescription
.
Description describe(Description description) => description.add('an instance of ${_name}');
Description describeMismatch(item, Description mismatchDescription, MatchState matchState, bool verbose) #
Generates a description of the matcher failed for a particular item, by appending the description to mismatchDescription. It does not check whether the item fails the match, as it is only called after a failed match. There may be additional info about the mismatch in matchState.
Description describeMismatch(item, Description mismatchDescription, MatchState matchState, bool verbose) => mismatchDescription.add('was ').addDescriptionOf(item);
bool matches(obj, MatchState matchState) #
Tests the matcher against a given item
and return true if the match succeeds; false otherwise.
matchState may be used to return additional info for
the use of describeMismatch
.
bool matches(obj, MatchState matchState) => obj is T;