StreamMatcher class abstract
A matcher that matches events from Streams or StreamQueue
s.
Stream matchers are designed to make it straightforward to create complex expectations for streams, and to interleave expectations with the rest of a test. They can be used on a Stream to match all events it emits:
expect(stream, emitsInOrder([
// Values match individual events.
"Ready.",
// Matchers also run against individual events.
startsWith("Loading took"),
// Stream matchers can be nested. This asserts that one of two events are
// emitted after the "Loading took" line.
emitsAnyOf(["Succeeded!", "Failed!"]),
// By default, more events are allowed after the matcher finishes
// matching. This asserts instead that the stream emits a done event and
// nothing else.
emitsDone
]));
It can also match a StreamQueue
, in which case it consumes the matched
events. The call to expect returns a Future that completes when the
matcher is done matching. You can await
this to consume different events
at different times:
var stdout = StreamQueue(stdoutLineStream);
// Ignore lines from the process until it's about to emit the URL.
await expectLater(stdout, emitsThrough('WebSocket URL:'));
// Parse the next line as a URL.
var url = Uri.parse(await stdout.next);
expect(url.host, equals('localhost'));
// You can match against the same StreamQueue multiple times.
await expectLater(stdout, emits('Waiting for connection...'));
Users can call StreamMatcher to create custom matchers.
Constructors
-
StreamMatcher(Future<
String?> matchQueue(StreamQueue), String description) -
Creates a new StreamMatcher described by
description
that matches events withmatchQueue
.factory
Properties
- description → String
-
The description of this matcher.
no setter
- 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.
inherited
-
describeMismatch(
dynamic item, Description mismatchDescription, Map matchState, bool verbose) → Description -
Builds a textual description of a specific mismatch.
inherited
-
matches(
dynamic item, Map matchState) → bool -
Does the matching of the actual vs expected values.
inherited
-
matchQueue(
StreamQueue queue) → Future< String?> -
Tries to match events emitted by
queue
. -
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