import { async , ComponentFixture , TestBed } from '@angular/core/testing' ; import { Observable } from 'rxjs/Rx' ; import { PostsComponent } from './posts.component' ; import { PostsService } from './posts.service' ; class FakePostsService { getAllPosts ( ) { return Observable . of ( [ { } , { } ] ) ; } } describe ( 'PostsComponent' , ( ) => { let component ; let fixture ; beforeEach ( async ( ( ) => { TestBed . configureTestingModule ( { declarations : [ PostsComponent ] , providers : [ { provide : PostsService , useClass : FakePostsService } ] } ) . compileComponents ( ) ; } ) ) ; beforeEach ( ( ) => { fixture = TestBed . createComponent ( PostsComponent ) ; component = fixture . componentInstance ; fixture . detectChanges ( ) ; } ) ; it ( 'should create' , ( ) => { expect ( component ) . toBeTruthy ( ) ; } ) ; } ) ;