1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
3 import { LogComponent } from './log.component';
4 import { HttpClientTestingModule } from '@angular/common/http/testing';
5 import { LogService } from './log.service';
6 import { MockBackend } from '@angular/http/testing';
7 import { BaseRequestOptions, Http } from '@angular/http';
8 import 'rxjs/add/observable/of';
9 import { Observable } from 'rxjs/Observable';
11 describe('LogComponent', () => {
12 let component: LogComponent;
13 let fixture: ComponentFixture<LogComponent>;
14 let logService:LogService;
16 beforeEach(async(() => {
17 TestBed.configureTestingModule({
18 declarations: [ LogComponent ],
19 imports: [HttpClientTestingModule],
20 // providers:[LogService,MockBackend,BaseRequestOptions,{
21 // porvide:Http,useFactory:(backend:MockBackend,defaultOptions:BaseRequestOptions)=>{
22 // return new Http(backend,defaultOptions);
24 // deps:[MockBackend,BaseRequestOptions],
31 fixture = TestBed.createComponent(LogComponent);
32 component = fixture.componentInstance;
33 fixture.detectChanges();
34 logService=TestBed.get(LogService);
37 it('should create', () => {
38 expect(component).toBeTruthy();
41 describe('should test subscribe',()=>{
42 it('should test ngOnInit method1',()=>{
43 component.reportType = "Dashboard";
45 expect(component.stepNo).toEqual("3");
49 it('should test ngOnInit method2',()=>{
50 component.reportType != "Dashboard";
52 expect(component.stepNo).toEqual("7");
55 it('should test subscribe method inside ngOnInit method',()=>{
56 let spy=spyOn(logService,'getLogData').and.returnValue(Observable.of('you object'));
58 expect(spy).toHaveBeenCalled();