title: Unit testing Angular 2 Service
body: <p>Im new to whole unit testing scene with Angular, so would be great if guys could point me in the direction.. Im trying to create a fake service and pass back data to which i can run a few simple test.. </p>
  
  <p>When I go to run the test it seems to fail with </p>
  
  <p>Server error
    at webpack:///~/rxjs/Subscriber.js:194:0 &lt;- config/karma-test-shim.js:20301</p>
  
  <p>I don't think it my webpack config.. Here is my code anway...</p>
  
  <pre><code>import { SearchModule } from './search.module';
  import { SearchService } from './search.services';
  import { HttpModule }    from '@angular/http'; 
  import { inject, TestBed } from '@angular/core/testing';  
  import { Observable } from 'rxjs/Observable';
  import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
  
  class SearchServiceMock {
  
  search() {
  
      return Observable.of(
          [
              {
              "title": "title_1",
              "artist": "artist_1",
              "release": "06/02/2016",
              "slug": "slug-1"
          },
          {
              "title": "title_2",
              "artist": "artist_1",
              "release": " 27/01/2017",
              "slug": "slug-2"
          },
          {
              "title": "title_3",
              "artist": "artist_3",
              "release": "17/02/2017",
              "slug": "slug-3"
          }
          ]
      )
  
  }
  
  }
  
  describe('Service: TracksServices', () =&gt; {
  
  let searchService: SearchService;
  
  beforeEach(() =&gt; TestBed.configureTestingModule({
      imports: [ SearchModule, HttpModule ],
          providers: [
          { provide: SearchService, useClass: SearchServiceMock },
      ]
  }));
  
  beforeEach(inject([SearchService], (s: any) =&gt; {
      searchService = s;
  }));
  
  it('Search results 3', () =&gt; {
  
      searchService.search('track 1', 1, 4).subscribe(
          (x:any) =&gt; {     
  
              // expect(x).toContain(track);
              expect(x.length).toEqual(3);
  
          }
      );
  
  });
  
  });
  </code></pre>
  
  <p>The test still seems to be getting the real service i think when I want to use a fake one</p>