countOf function

StreamMatcher countOf(
  1. int expectedCount
)

Implementation

StreamMatcher countOf(int expectedCount) {
  return StreamMatcher((queue) async {
    var eventsCount = 0;
    await queue.withTransaction((copy) async {
      while (await copy.hasNext) {
        eventsCount++;
        try {
          await copy.next;
        } catch (_) {
          // Ignore errors events.
        }
      }
      return false;
    });

    if (eventsCount != expectedCount) {
      return 'Emitted <$eventsCount> events';
    }
    return null;
  }, 'have <$expectedCount> event');
}