StreamMatcher class
A matcher that matches events from Streams or StreamQueues.
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 = new StreamQueue(stdoutLineStream);
// Ignore lines from the process until it's about to emit the URL.
await expect(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 expect(stdout, emits("Waiting for connection..."));
Users can call new StreamMatcher to create custom matchers.
Constructors
-
StreamMatcher(Future<
String> matchQueue(StreamQueue queue), String description) -
Creates a new StreamMatcher described by
description
that matches events withmatchQueue
. [...]factory
Properties
- description → String
-
The description of this matcher. [...]
read-only
- 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
-
matchQueue(
StreamQueue queue) → Future< String> -
Tries to match events emitted by
queue
. [...] -
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
-
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