First of all you need to configure TestBed . There are more TestComponentBuilder . With TestBed this is like setting up @NgModule from scratch, just for a test environment. This means that you add the component under test in declarations , add all the providers to the provider and import everything into imports .
To set up a background backend for an Http provider, you simply create Http from MockBackend .
beforeEach(() => { TestBed.configureTestingModule({ imports: [ HttpModule ], declarations: [ RouteListComponent ], providers: [ MockBackend, BaseRequestOptions, { provide: Http, useFactory: (backend: MockBackend, options: BaseRequestOptions) => { return new Http(backend, options); }, deps: [ MockBackend, BaseRequestOptions ] } ] }) })
This should be for configuration, assuming you don't need any other vendors or imports that I don't know about.
For the test, you first need to do the async test, since you will perform asynchronous operations in the test. This has not changed with RC, you are just using async . If the component uses templateUrl (and you do not use Webpack), you will need to call TestBed.compileComponents() , otherwise there is no need. After that, you can create the component using TestBed.createComponent
let fixture: ComponentFixture<RouteListComponent>; let component: RouteListComponent; beforeEach(async(() => { TestBed.configureTestingModule({ ... }) .compileComponents().then(() => { fixture = TestBed.createComponent(RouteListComponent); component = fixture.componentInstance; fixture.detectChanges(); }); })); it('...', async(inject([MockBackend], (backend: MockBackend) => { })))
Almost everything related to testing can be imported from @angular/core/testing . Your use of MockBackend will still be the same.
Another note: you do not need to call component.ngOnInit . This is called a wireframe when you call fixture.detectChanges()
See also: