title: Dart: How to test if stream emits elements at a certain time?
body: <p>I try to test a function <code>Stream transform(Stream input)</code>. How can I test if the returned stream emits elements at a certain time?</p>
  
  <p>In <a href="https://github.com/Reactive-Extensions/RxJS" rel="nofollow">RxJS</a> (JavaScript) I can use a <a href="https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/testing/testscheduler.md" rel="nofollow">TestScheduler</a> to emit elements on the input stream at a certain time and test if they are emitted on the output stream at a certain time. In this <a href="https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/testing/testscheduler.md#example" rel="nofollow">example</a>, the transform function is passed to <code>scheduler.startWithCreate</code>:</p>
  
  <pre class="lang-js prettyprint-override"><code>var scheduler = new Rx.TestScheduler();
  
  // Create hot observable which will start firing
  var xs = scheduler.createHotObservable(
    onNext(150, 1),
    onNext(210, 2),
    onNext(220, 3),
    onCompleted(230)
  );
  
  // Note we'll start at 200 for subscribe, hence missing the 150 mark
  var res = scheduler.startWithCreate(function () {
    return xs.map(function (x) { return x * x });
  });
  
  // Implement collection assertion
  collectionAssert.assertEqual(res.messages, [
    onNext(210, 4),
    onNext(220, 9),
    onCompleted(230)
  ]);
  
  // Check for subscribe/unsubscribe
  collectionAssert.assertEqual(xs.subscriptions, [
    subscribe(200, 230)
  ]);
  </code></pre>