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.
StreamQueue queue) → Future< String>
Tries to match events emitted by
Description description) → Description
Builds a textual description of the matcher.
dynamic item, Description mismatchDescription, Map matchState, bool verbose) → Description
Builds a textual description of a specific mismatch. [...]
dynamic item, Map matchState) → bool
Does the matching of the actual vs expected values. [...]
Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
) → String
Returns a string representation of this object.
dynamic other) → bool
The equality operator.