title: How to unit test Observable.interval with RxJS 5?
body: <p>I have a very simple periodic activity which is scheduled by RxJS 5 and I'm a bit curious about how to unit test this type of code using RxJS 5:</p>
  
  <pre><code>start() {
    this._subscription = Observable
                          .interval(this._interval, SchedulerProvider.getScheduler())
                          .subscribe(_ =&gt; this.doSomething());
  }
  stop() {
    this._subscription.unsubscribe();
  }
  </code></pre>
  
  <p>What I tried is to stub my <code>SchedulerProvider.getScheduler</code> function to return a <code>new TestScheduler()</code> during my tests (by default it just returns <code>undefined</code> so the production code just uses the default scheduler) - and then try to setup virtual "ticks" for the interval:</p>
  
  <pre><code>myTestSchedulerInstance.createColdObservable('xxxxxxxx', {x: 1}); // tick ten times
  unitUnderTest.start();
  myTestSchedulerInstance.flush();
  ... assert that doSomething() should be called 10 times ....
  </code></pre>
  
  <p>But it doesn't work. I guess <code>createColdObservable</code> and <code>createHotObservable</code> just returns a new observable based on the marble-syntax input string - but this doesn't affect my interval.</p>
  
  <p>I went through the docs and I'm a bit confused now about the marble testing in RxJS 5, because the examples in the docs (and everywhere else) look like this:</p>
  
  <ul>
  <li>in the first step: create a test scheduler</li>
  <li>then create a cold/hot observable using this scheduler</li>
  <li>your unit under test applies some operators on the created observable - which produces another observable</li>
  <li>then you assert on the resulting observable using <code>expectObservable</code></li>
  </ul>
  
  <p>But my use-case is different. I don't want to return the <code>Observable.interval</code>, because I'm only interested in the side-effect of my subscription. Is it possible to write such a test using RxJS 5?</p>
  
  <p>The only alternatives which I see right now:</p>
  
  <ul>
  <li>use sinon's fake timers</li>
  <li>inside <code>start()</code>, map the side effect to the interval and after subscribing to it, return the observable containing the side effect -> and use it in the assertion using <code>expectObservable</code></li>
  </ul>
  
  <p>But each solution seems to be a bit messy.</p>