title: Unit testing an observable in Angular 2
body: <p>What is the correct way of unit testing a service returning an Observable result in Angular 2? Let's say we have a getCars method in a CarService service class:</p>
  
  <pre><code>...
  export class CarService{
      ...
      getCars():Observable&lt;any&gt;{
          return this.http.get("http://someurl/cars").map( res =&gt; res.json() );
      }
      ...
  }
  </code></pre>
  
  <p>If I try to write the tests in the following way I get the warning: 'SPEC HAS NO EXPECTATIONS':</p>
  
  <pre><code>it('retrieves all the cars', inject( [CarService], ( carService ) =&gt; {
       carService.getCars().subscribe( result =&gt; {         
           expect(result.length).toBeGreaterThan(0);
       } );       
  }) );
  </code></pre>
  
  <p>Using injectAsync does not help because it works with <code>Promise</code> objects as far as I could see.</p>