expect library Null safety
Classes
- CustomMatcher
- 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.
- Description
- Matchers build up their error messages by appending to Description objects.
-
isInstanceOf<
T> - DEPRECATED Use isA instead.
- Matcher
- The base class for all matchers.
- StreamMatcher
- A matcher that matches events from Streams or StreamQueues.
- StringDescription
- The default implementation of Description. This should rarely need substitution, although conceivably it is a place where other languages could be supported.
-
TypeMatcher<
T> - A Matcher subclass that supports validating the Type of the target object.
Constants
- anything → const Matcher
-
A matcher that matches any value.
_IsAnything() -
isArgumentError
→ const TypeMatcher<
ArgumentError> -
A matcher for
ArgumentError.TypeMatcher<ArgumentError>() -
isCastError
→ const TypeMatcher<
CastError> -
A matcher for
CastError.Deprecated('CastError has been deprecated in favor of TypeError. ' 'Use `isA<TypeError>()` or, if you need compatibility with older SDKs, ' 'use `isA<CastError>()` and ignore the deprecation.')">@Deprecated('CastError has been deprecated in favor of TypeError. ' 'Use `isA<TypeError>()` or, if you need compatibility with older SDKs, ' 'use `isA<CastError>()` and ignore the deprecation.')TypeMatcher<CastError>() -
isConcurrentModificationError
→ const TypeMatcher<
ConcurrentModificationError> -
A matcher for
ConcurrentModificationError.TypeMatcher<ConcurrentModificationError>() -
isCyclicInitializationError
→ const TypeMatcher<
CyclicInitializationError> -
A matcher for
CyclicInitializationError.TypeMatcher<CyclicInitializationError>() - isEmpty → const Matcher
-
Returns a matcher that matches the isEmpty property.
_Empty() -
isException
→ const TypeMatcher<
Exception> -
A matcher for
Exception.TypeMatcher<Exception>() - isFalse → const Matcher
-
A matcher that matches anything except the Boolean value true.
_IsFalse() -
isFormatException
→ const TypeMatcher<
FormatException> -
A matcher for
FormatException.TypeMatcher<FormatException>() -
isList
→ const TypeMatcher<
List> -
A matcher for
List.TypeMatcher<List>() -
isMap
→ const TypeMatcher<
Map> -
A matcher for
Map.TypeMatcher<Map>() - isNaN → const Matcher
-
A matcher that matches the numeric value NaN.
_IsNaN() - isNegative → const Matcher
-
A matcher which matches if the match argument is negative.
_OrderingMatcher(0, false, true, false, 'a negative value', false) - isNonNegative → const Matcher
-
A matcher which matches if the match argument is zero or positive.
_OrderingMatcher(0, true, false, true, 'a non-negative value', false) - isNonPositive → const Matcher
-
A matcher which matches if the match argument is zero or negative.
_OrderingMatcher(0, true, true, false, 'a non-positive value', false) - isNonZero → const Matcher
-
A matcher which matches if the match argument is non-zero.
_OrderingMatcher(0, false, true, true, 'a value not equal to') -
isNoSuchMethodError
→ const TypeMatcher<
NoSuchMethodError> -
A matcher for
NoSuchMethodError.TypeMatcher<NoSuchMethodError>() - isNotEmpty → const Matcher
-
Returns a matcher that matches the isNotEmpty property.
_NotEmpty() - isNotNaN → const Matcher
-
A matcher that matches any non-NaN value.
_IsNotNaN() - isNotNull → const Matcher
-
A matcher that matches any non-null value.
_IsNotNull() - isNull → const Matcher
-
A matcher that matches any null value.
_IsNull() -
isNullThrownError
→ const TypeMatcher<
NullThrownError> -
A matcher for
NullThrownError.TypeMatcher<NullThrownError>() - isPositive → const Matcher
-
A matcher which matches if the match argument is positive.
_OrderingMatcher(0, false, false, true, 'a positive value', false) -
isRangeError
→ const TypeMatcher<
RangeError> -
A matcher for
RangeError.TypeMatcher<RangeError>() -
isStateError
→ const TypeMatcher<
StateError> -
A matcher for
StateError.TypeMatcher<StateError>() - isTrue → const Matcher
-
A matcher that matches the Boolean value true.
_IsTrue() -
isUnimplementedError
→ const TypeMatcher<
UnimplementedError> -
A matcher for
UnimplementedError.TypeMatcher<UnimplementedError>() -
isUnsupportedError
→ const TypeMatcher<
UnsupportedError> -
A matcher for
UnsupportedError.TypeMatcher<UnsupportedError>() - isZero → const Matcher
-
A matcher which matches if the match argument is zero.
_OrderingMatcher(0, true, false, false, 'a value equal to') - returnsNormally → const Matcher
-
A matcher that matches a function call against no exception.
_ReturnsNormally() - throwsArgumentError → const Matcher
-
A matcher for functions that throw ArgumentError.
Throws(isArgumentError) - throwsConcurrentModificationError → const Matcher
-
A matcher for functions that throw ConcurrentModificationError.
Throws(isConcurrentModificationError) - throwsCyclicInitializationError → const Matcher
-
A matcher for functions that throw CyclicInitializationError.
Throws(isCyclicInitializationError) - throwsException → const Matcher
-
A matcher for functions that throw Exception.
Throws(isException) - throwsFormatException → const Matcher
-
A matcher for functions that throw FormatException.
Throws(isFormatException) - throwsNoSuchMethodError → const Matcher
-
A matcher for functions that throw NoSuchMethodError.
Throws(isNoSuchMethodError) - throwsNullThrownError → const Matcher
-
A matcher for functions that throw NullThrownError.
Throws(isNullThrownError) - throwsRangeError → const Matcher
-
A matcher for functions that throw RangeError.
Throws(isRangeError) - throwsStateError → const Matcher
-
A matcher for functions that throw StateError.
Throws(isStateError) - throwsUnimplementedError → const Matcher
-
A matcher for functions that throw Exception.
Throws(isUnimplementedError) - throwsUnsupportedError → const Matcher
-
A matcher for functions that throw UnsupportedError.
Throws(isUnsupportedError)
Properties
- completes → Matcher
-
Matches a Future that completes successfully with any value.
final
- doesNotComplete → Matcher
-
Matches a Future that does not complete.
final
- emitsDone → StreamMatcher
-
Returns a StreamMatcher that asserts that the stream emits a "done" event.
final
- neverCalled → Null Function([Object?, Object?, Object?, Object?, Object?, Object?, Object?, Object?, Object?, Object?])
-
Returns a function that causes the test to fail if it's called.
read-only
Functions
-
addStateInfo(
Map matchState, Map values) → void - Useful utility for nesting match states.
-
allOf(
Object? arg0, [Object? arg1, Object? arg2, Object? arg3, Object? arg4, Object? arg5, Object? arg6]) → Matcher - This returns a matcher that matches if all of the matchers passed as arguments (up to 7) match.
-
anyElement(
Object? valueOrMatcher) → Matcher -
Returns a matcher which matches Iterables in which at least one
element matches the given
valueOrMatcher. -
anyOf(
Object? arg0, [Object? arg1, Object? arg2, Object? arg3, Object? arg4, Object? arg5, Object? arg6]) → Matcher - Matches if any of the given matchers evaluate to true.
-
closeTo(
num value, num delta) → Matcher -
Returns a matcher which matches if the match argument is within
deltaof somevalue. -
collapseWhitespace(
String string) → String - Utility function to collapse whitespace runs to single spaces and strip leading/trailing whitespace.
-
completion(
dynamic matcher, [String? description]) → Matcher -
Matches a Future that completes successfully with a value that matches
matcher. -
contains(
Object? expected) → Matcher - Returns a matcher that matches if the match argument contains the expected value.
-
containsAll(
Iterable expected) → Matcher -
Matches Iterables which contain an element matching every value in
expectedin any order, and may contain additional values. -
containsAllInOrder(
Iterable expected) → Matcher -
Matches Iterables which contain an element matching every value in
expectedin the same order, but may contain additional values interleaved throughout. -
containsPair(
Object? key, Object? valueOrMatcher) → Matcher -
Returns a matcher which matches maps containing the key-value pair
with
key=>valueOrMatcher. -
containsValue(
Object? value) → Matcher -
Returns a matcher which matches maps containing the given
value. -
emits(
dynamic matcher) → StreamMatcher -
Returns a StreamMatcher for
matcher. -
emitsAnyOf(
Iterable matchers) → StreamMatcher -
Returns a StreamMatcher that matches the stream if at least one of
matchersmatches. -
emitsError(
dynamic matcher) → StreamMatcher -
Returns a StreamMatcher that matches a single error event that matches
matcher. -
emitsInAnyOrder(
Iterable matchers) → StreamMatcher -
Returns a StreamMatcher that matches the stream if each matcher in
matchersmatches, in any order. -
emitsInOrder(
Iterable matchers) → StreamMatcher -
Returns a StreamMatcher that matches the stream if each matcher in
matchersmatches, one after another. -
emitsThrough(
dynamic matcher) → StreamMatcher -
Returns a StreamMatcher that matches any number of events followed by
events that match
matcher. -
endsWith(
String suffixString) → Matcher -
Returns a matcher that matches if the match argument is a string and
ends with
suffixString. -
equals(
Object? expected, [int limit = 100]) → Matcher -
Returns a matcher that matches if the value is structurally equal to
expected. -
equalsIgnoringCase(
String value) → Matcher -
Returns a matcher which matches if the match argument is a string and
is equal to
valuewhen compared case-insensitively. -
equalsIgnoringWhitespace(
String value) → Matcher -
Returns a matcher which matches if the match argument is a string and
is equal to
value, ignoring whitespace. -
escape(
String str) → String -
Returns
strwith all whitespace characters represented as their escape sequences. -
everyElement(
Object? valueOrMatcher) → Matcher -
Returns a matcher which matches Iterables in which all elements
match the given
valueOrMatcher. -
expect(
dynamic actual, dynamic matcher, {String? reason, dynamic skip, bool verbose = false, ErrorFormatter? formatter}) → void -
Assert that
actualmatchesmatcher. -
expectAsync0<
T> (T callback(), {int count = 1, int max = 0, String? id, String? reason}) → Func0< T> -
Informs the framework that the given
callbackof arity 0 is expected to be calledcountnumber of times (by default 1). -
expectAsync1<
T, A> (T callback(A), {int count = 1, int max = 0, String? id, String? reason}) → Func1< T, A> -
Informs the framework that the given
callbackof arity 1 is expected to be calledcountnumber of times (by default 1). -
expectAsync2<
T, A, B> (T callback(A, B), {int count = 1, int max = 0, String? id, String? reason}) → Func2< T, A, B> -
Informs the framework that the given
callbackof arity 2 is expected to be calledcountnumber of times (by default 1). -
expectAsync3<
T, A, B, C> (T callback(A, B, C), {int count = 1, int max = 0, String? id, String? reason}) → Func3< T, A, B, C> -
Informs the framework that the given
callbackof arity 3 is expected to be calledcountnumber of times (by default 1). -
expectAsync4<
T, A, B, C, D> (T callback(A, B, C, D), {int count = 1, int max = 0, String? id, String? reason}) → Func4< T, A, B, C, D> -
Informs the framework that the given
callbackof arity 4 is expected to be calledcountnumber of times (by default 1). -
expectAsync5<
T, A, B, C, D, E> (T callback(A, B, C, D, E), {int count = 1, int max = 0, String? id, String? reason}) → Func5< T, A, B, C, D, E> -
Informs the framework that the given
callbackof arity 5 is expected to be calledcountnumber of times (by default 1). -
expectAsync6<
T, A, B, C, D, E, F> (T callback(A, B, C, D, E, F), {int count = 1, int max = 0, String? id, String? reason}) → Func6< T, A, B, C, D, E, F> -
Informs the framework that the given
callbackof arity 6 is expected to be calledcountnumber of times (by default 1). -
expectAsyncUntil0<
T> (T callback(), bool isDone(), {String? id, String? reason}) → Func0< T> -
Informs the framework that the given
callbackof arity 0 is expected to be called untilisDonereturns true. -
expectAsyncUntil1<
T, A> (T callback(A), bool isDone(), {String? id, String? reason}) → Func1< T, A> -
Informs the framework that the given
callbackof arity 1 is expected to be called untilisDonereturns true. -
expectAsyncUntil2<
T, A, B> (T callback(A, B), bool isDone(), {String? id, String? reason}) → Func2< T, A, B> -
Informs the framework that the given
callbackof arity 2 is expected to be called untilisDonereturns true. -
expectAsyncUntil3<
T, A, B, C> (T callback(A, B, C), bool isDone(), {String? id, String? reason}) → Func3< T, A, B, C> -
Informs the framework that the given
callbackof arity 3 is expected to be called untilisDonereturns true. -
expectAsyncUntil4<
T, A, B, C, D> (T callback(A, B, C, D), bool isDone(), {String? id, String? reason}) → Func4< T, A, B, C, D> -
Informs the framework that the given
callbackof arity 4 is expected to be called untilisDonereturns true. -
expectAsyncUntil5<
T, A, B, C, D, E> (T callback(A, B, C, D, E), bool isDone(), {String? id, String? reason}) → Func5< T, A, B, C, D, E> -
Informs the framework that the given
callbackof arity 5 is expected to be called untilisDonereturns true. -
expectAsyncUntil6<
T, A, B, C, D, E, F> (T callback(A, B, C, D, E, F), bool isDone(), {String? id, String? reason}) → Func6< T, A, B, C, D, E, F> -
Informs the framework that the given
callbackof arity 6 is expected to be called untilisDonereturns true. -
expectLater(
dynamic actual, dynamic matcher, {String? reason, dynamic skip}) → Future - Just like expect, but returns a Future that completes when the matcher has finished matching.
-
fail(
String message) → Never -
Convenience method for throwing a new TestFailure with the provided
message. -
greaterThan(
Object value) → Matcher -
Returns a matcher which matches if the match argument is greater
than the given
value. -
greaterThanOrEqualTo(
Object value) → Matcher -
Returns a matcher which matches if the match argument is greater
than or equal to the given
value. -
hasLength(
Object? matcher) → Matcher -
Returns a matcher that matches if an object has a length property
that matches
matcher. -
inClosedOpenRange(
num low, num high) → Matcher -
Returns a matcher which matches if the match argument is greater
than or equal to a
lowand less thanhigh. -
inExclusiveRange(
num low, num high) → Matcher -
Returns a matcher which matches if the match argument is greater
than
lowand less thanhigh. -
inInclusiveRange(
num low, num high) → Matcher -
Returns a matcher which matches if the match argument is greater
than or equal to
lowand less than or equal tohigh. -
inOpenClosedRange(
num low, num high) → Matcher -
Returns a matcher which matches if the match argument is greater
than
lowand less than or equal tohigh. -
isA<
T> () → TypeMatcher< T> -
Returns a matcher that matches objects with type
T. -
isIn(
Object? expected) → Matcher - Returns a matcher that matches if the match argument is in the expected value. This is the converse of contains.
-
isNot(
Object? valueOrMatcher) → Matcher -
Returns a matcher that inverts
valueOrMatcherto its logical negation. -
lessThan(
Object value) → Matcher -
Returns a matcher which matches if the match argument is less
than the given
value. -
lessThanOrEqualTo(
Object value) → Matcher -
Returns a matcher which matches if the match argument is less
than or equal to the given
value. -
matches(
Pattern re) → Matcher -
Returns a matcher that matches if the match argument is a string and
matches the regular expression given by
re. -
mayEmit(
dynamic matcher) → StreamMatcher -
Returns a StreamMatcher that allows (but doesn't require)
matcherto match the stream. -
mayEmitMultiple(
dynamic matcher) → StreamMatcher -
Returns a StreamMatcher that matches any number of events that match
matcher. -
neverEmits(
dynamic matcher) → StreamMatcher -
Returns a StreamMatcher that matches a stream that never matches
matcher. -
orderedEquals(
Iterable expected) → Matcher -
Returns a matcher which matches Iterables that have the same
length and the same elements as
expected, in the same order. -
pairwiseCompare<
S, T> (Iterable< S> expected, bool comparator(S, T), String description) → Matcher - A pairwise matcher for Iterables.
-
predicate<
T> (bool f(T), [String description = 'satisfies function']) → Matcher - Returns a matcher that uses an arbitrary function that returns true or false for the actual value.
-
prints(
dynamic matcher) → Matcher -
Matches a Function that prints text that matches
matcher. -
same(
Object? expected) → Matcher -
Returns a matches that matches if the value is the same instance
as
expected, using identical. -
startsWith(
String prefixString) → Matcher -
Returns a matcher that matches if the match argument is a string and
starts with
prefixString. -
stringContainsInOrder(
List< String> substrings) → Matcher -
Returns a matcher that matches if the match argument is a string and
contains a given list of
substringsin relative order. -
throwsA(
dynamic matcher) → Matcher - This can be used to match three kinds of objects:
-
unorderedEquals(
Iterable expected) → Matcher -
Returns a matcher which matches Iterables that have the same length and
the same elements as
expected, but not necessarily in the same order. -
unorderedMatches(
Iterable expected) → Matcher -
Returns a matcher which matches Iterables whose elements match the
matchers in
expected, but not necessarily in the same order. -
wrapMatcher(
Object? valueOrMatcher) → Matcher - Takes an argument and returns an equivalent Matcher.
Typedefs
-
Func0<
T> = T Function() -
Func1<
T, A> = T Function([A a]) -
Func2<
T, A, B> = T Function([A a, B b]) -
Func3<
T, A, B, C> = T Function([A a, B b, C c]) -
Func4<
T, A, B, C, D> = T Function([A a, B b, C c, D d]) -
Func5<
T, A, B, C, D, E> = T Function([A a, B b, C c, D d, E e]) -
Func6<
T, A, B, C, D, E, F> = T Function([A a, B b, C c, D d, E e, F f])