Я пытаюсь написать тестовые примеры для углового приложения. У меня есть служба, возвращающая Observable, которую я сейчас пытаюсь проверить.
Я пытался использовать Observable.of (), который, похоже, не работал.
Ниже приведены файлы ..
метод обслуживания, возвращающий наблюдаемый, используя httpclient. я пытался шпионить
с возвращаемым значением наблюдаемого массива.
терминально-carding.service.ts
getTerminalCompanies() {
return this.http.get(this.maintenanceSharedService.getTerminalCompaniesUrl())
.map(this.extractData)
.catch(this.handleGetTerminalCompaniesError)
}
терминально-carding.component.spec.ts
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AgGridModule } from 'ag-grid-angular/main';
import { TableWidgetComponent } from '../../../widgets/table-widget/table-widget.component';
import { TerminalCardingComponent } from './terminal-carding.component';
import { TerminalCardingService } from './terminal-carding.service';
import { AppService } from './../../../app.service';
import { UtilService } from '../../../shared/util.service';
import { DashboardSharedService } from './../../../shared/dashboard-shared.service';
import { TableWidgetService } from '../../../widgets/table-widget/table-widget.service';
import { SecuritySharedService } from '../../../shared/security-shared.service';
import { MaintenanceSharedService } from '../../../shared/maintenance-shared.service';
import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { Observable} from 'rxjs/observable';
import { HttpClientModule } from '@angular/common/http';
import { BaseHttpClientService } from '../../../shared/common/base-http-client.service';
fdescribe('TerminalCardingComponent', () => {
let component: TerminalCardingComponent;
let fixture: ComponentFixture<TerminalCardingComponent>;
let maintenanceSharedService: MaintenanceSharedService;
let service: TerminalCardingService;
let getMaintenanceModuleAuthPermissionsSpy;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
AgGridModule.withComponents([]),
HttpClientModule,
FormsModule
],
declarations: [
TerminalCardingComponent,
TableWidgetComponent,
],
providers: [
AppService,
UtilService,
DashboardSharedService,
TableWidgetService,
SecuritySharedService,
MaintenanceSharedService,
TerminalCardingService,
BaseHttpClientService
],
schemas: [ CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA ]
})
.compileComponents();
}));
beforeEach(() => {
service = TestBed.get( TerminalCardingService );
maintenanceSharedService = TestBed.get( MaintenanceSharedService );
getMaintenanceModuleAuthPermissionsSpy = spyOn(maintenanceSharedService, 'getMaintenanceModuleAuthPermissions').and.returnValue({});
fixture = TestBed.createComponent(TerminalCardingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should be created', () => {
expect(component).toBeTruthy();
});
it('should resolve test data', async(() => {
const terminalCompanies = [{
terminalCompany: 'aaa'
},
{
terminalCompany: 'bbb'
},
{
terminalCompany: 'ccc'
}];
const spy = spyOn(service, 'getTerminalCompanies').and.returnValue(Observable.of(terminalCompanies));
component.ngOnInit();
fixture.detectChanges();
console.log(component.terminalCompanies[0].terminalCompany);
expect(component.terminalCompanies[0].terminalCompany).toEqual(terminalCompanies[0].terminalCompany);
}));
});
Error: i am getting following error....
Failed: observable_1.Observable.of is not a function