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..
When I go to run the test it seems to fail with
Server error at webpack:///~/rxjs/Subscriber.js:194:0 <- config/karma-test-shim.js:20301
I don't think it my webpack config.. Here is my code anway...
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', () => {
let searchService: SearchService;
beforeEach(() => TestBed.configureTestingModule({
imports: [ SearchModule, HttpModule ],
providers: [
{ provide: SearchService, useClass: SearchServiceMock },
]
}));
beforeEach(inject([SearchService], (s: any) => {
searchService = s;
}));
it('Search results 3', () => {
searchService.search('track 1', 1, 4).subscribe(
(x:any) => {
// expect(x).toContain(track);
expect(x.length).toEqual(3);
}
);
});
});
The test still seems to be getting the real service i think when I want to use a fake one