Unit testing 故障测试传单图(角度5)

Unit testing 故障测试传单图(角度5),unit-testing,leaflet,karma-jasmine,angular5,Unit Testing,Leaflet,Karma Jasmine,Angular5,我正试图为传单图编写几个测试,但似乎无法找到正确的执行方法而不会出错 beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ CommonModule, FormsModule, MomentModule, NgbModule.forRoot(), ApiModule

我正试图为传单图编写几个测试,但似乎无法找到正确的执行方法而不会出错

beforeEach(async(() => {
    TestBed.configureTestingModule({
        imports: [
            CommonModule,
            FormsModule,
            MomentModule,
            NgbModule.forRoot(),
            ApiModule.forRoot(true),
            ReactiveFormsModule,
            RouterTestingModule,
            SharedModule.forRoot(),
            NgbModalModule,
            ColorPickerModule,
            MapModule
        ],
        declarations: [
            RoutesManagerComponent
        ]
    }).compileComponents();
}));

beforeEach(() => {
    this.fixture = TestBed.createComponent(RoutesManagerComponent);
    this.compInstance = this.fixture.componentInstance;
    this.compiled = this.fixture.debugElement.nativeElement;
    this.routeService = TestBed.get(RouteService);

    spyOn(this.routeService, 'getDropdownOptions').and.callThrough();
    spyOn(this.routeService, 'create').and.callThrough();
    spyOn(this.routeService, 'update').and.callThrough();

    spyOn(this.compInstance, 'clearMap').and.callThrough();
    spyOn(this.compInstance, 'loadStops').and.callThrough();
    spyOn(this.compInstance, 'loadRoute').and.callThrough();
    spyOn(this.compInstance, 'createLeg').and.callThrough();
    spyOn(this.compInstance, 'setRoute').and.callThrough();
    spyOn(this.compInstance, 'ngOnInit').and.callThrough();
    spyOn(this.compInstance, 'save').and.callThrough();
    spyOn(this.compInstance, 'removeLeg').and.callThrough();
    spyOn(this.compInstance, 'onMapClicked').and.callThrough();
    spyOn(this.compInstance, 'addPointToEndOfLegPath').and.callThrough();
    spyOn(this.compInstance, 'addWaypointToLegAtIdx').and.callThrough();
    spyOn(this.compInstance, 'onStopClicked').and.callThrough();
    spyOn(this.compInstance, 'convertPointToWaypoint').and.callThrough();
    spyOn(this.compInstance, 'findNearestSegmentOnPath').and.callThrough();
    spyOn(this.compInstance, 'findClosestPointOnPathForLeg').and.callThrough();
    spyOn(this.compInstance, 'createWaypoint').and.callThrough();
    spyOn(this.compInstance, 'OnWaypointMoved').and.callThrough();
    spyOn(this.compInstance, 'OnWaypointMoveCompleted').and.callThrough();
    spyOn(this.compInstance, 'appendLegToRoute').and.callThrough();
    spyOn(this.compInstance, 'updateLegDurationAndDistance').and.callThrough();
    spyOn(this.compInstance, 'changeRouteColor').and.callThrough()
    spyOn(this.compInstance, 'getCoordsPriorToNewWaypoint').and.callThrough();
    spyOn(this.compInstance, 'findPath').and.callThrough();

    this.fixture.detectChanges();
});

it(`should define component instance`, (done => {
    this.compInstance.mapComponent.getNativeInstance().then(map => {
        expect(this.fixture.componentInstance).toBeDefined();
        expect(this.compInstance.ngOnInit).toHaveBeenCalled();
        expect(this.routeService.getDropdownOptions).toHaveBeenCalled();

        expect(this.fixture.componentInstance.messages).not.toBeNull();
        expect(this.fixture.componentInstance.messages.length).toEqual(0);
        done();
    });
}));

it(`should contain the correct leg when clicking stops`, (done => {
    this.compInstance.mapComponent.getNativeInstance().then(map => {
        this.compInstance.stopLayer.getLayers()[0].fire('click', { latlng: <any>([31.2284724615694, -85.4321765899658]) });
        this.compInstance.stopLayer.getLayers()[1].fire('click', { latlng: <any>([31.2490940369638, 85.4247093200683]) });

        expect(this.compInstance.onStopClicked).toHaveBeenCalled();

        expect(this.fixture.componentInstance.routeLegs[0].origin_stop).toEqual(
            { id: 1, name: 'Org1_stop1', code: 'o1-one', description: 'org1 first stop', url: null, location_type: 'stop', has_wheelchair_boarding: null, geometry: Object({ type: 'Point', coordinates: [-85.4321765899658, 31.2284724615694] }), boundary: Object({ type: 'Polygon', coordinates: [[[-85.4324126243591, 31.2282339294713], [-85.4318976402283, 31.2282339294713], [-85.4318976402283, 31.2288486071163], [-85.4324126243591, 31.2288486071163], [-85.4324126243591, 31.2282339294713]]] }) }
        );

        expect(this.fixture.componentInstance.routeLegs[0].destination_stop).toEqual(
            { id: 2, name: 'Org1_stop2', code: 'o1-two', description: 'org1 second stop', url: null, location_type: 'stop', has_wheelchair_boarding: null, geometry: Object({ type: 'Point', coordinates: [-85.4247093200683, 31.2490940369638] }), boundary: Object({ type: 'Polygon', coordinates: [[[-85.4248702526092, 31.2489472800928], [-85.4245215654373, 31.2489472800928], [-85.4245215654373, 31.2493416886665], [-85.4248702526092, 31.2493416886665], [-85.4248702526092, 31.2489472800928]]] }) }
        );

        this.fixture.detectChanges();

        expect(this.compInstance.onStopClicked).toHaveBeenCalled();
        expect(this.compInstance.appendLegToRoute).toHaveBeenCalled();
        expect(this.compInstance.updateLegDurationAndDistance).toHaveBeenCalled();

        done();
    });
}));

it(`should clear map when button is clicked`, (done => {
    this.compInstance.mapComponent.getNativeInstance().then(map => {
        this.compiled.querySelector('#clear-btn').click();
        expect(this.compInstance.clearMap).toHaveBeenCalled();
        done();
    });
}));
beforeach(异步(()=>{
TestBed.configureTestingModule({
进口:[
公共模块,
FormsModule,
动量模块,
NgbModule.forRoot(),
apimule.forRoot(true),
反应形式模块,
路由器测试模块,
SharedModule.forRoot(),
NgbModalModule,
颜色选择器模块,
映射模块
],
声明:[
路由管理组件
]
}).compileComponents();
}));
在每个之前(()=>{
this.fixture=TestBed.createComponent(RouteManagerComponent);
this.compInstance=this.fixture.componentInstance;
this.compiled=this.fixture.debugElement.nativeElement;
this.routeService=TestBed.get(routeService);
spyOn(this.routeService,'getDropdownOptions')。和.callThrough();
spyOn(this.routeService,'create')。和.callThrough();
spyOn(this.routeService,'update')。和.callThrough();
spyOn(this.compInstance,'clearMap')。和.callThrough();
spyOn(this.compInstance,'loadStops')。和.callThrough();
spyOn(this.compInstance,'loadRoute')。和.callThrough();
spyOn(this.compInstance,'createLeg')。和.callThrough();
spyOn(this.compInstance,'setRoute')。和.callThrough();
spyOn(this.compInstance,'ngOnInit')。和.callThrough();
spyOn(this.compInstance,'save')。和.callThrough();
spyOn(this.compInstance,'removeLeg')和.callThrough();
spyOn(this.compInstance,'onMapClicked')和.callThrough();
spyOn(this.compInstance,'addPointToEndOfLegPath')。和.callThrough();
spyOn(this.compInstance,'addWaypointToLegAtIdx')。和.callThrough();
spyOn(this.compInstance,'onStopClicked')。和.callThrough();
spyOn(this.compInstance,'convertPointToWaypoint')。和.callThrough();
spyOn(this.compInstance,'findNearestSegmentOnPath')。和.callThrough();
spyOn(this.compInstance,'findClosestPointOnPathForLeg')。和.callThrough();
spyOn(this.compInstance,'createWaypoint')。和.callThrough();
spyOn(this.compInstance,'OnWaypointMoved')。和.callThrough();
spyOn(this.compInstance,'OnWaypointMoveCompleted')。和.callThrough();
spyOn(this.compInstance,'appendLegToRoute')。和.callThrough();
spyOn(this.compInstance,'updateLegDurationAndDistance')。和.callThrough();
spyOn(this.compInstance,'changeRouteColor')。和.callThrough()
spyOn(this.compInstance,'getCoordsPriorToNewWaypoint')。和.callThrough();
spyOn(this.compInstance,'findPath')。和.callThrough();
this.fixture.detectChanges();
});
它(`应该定义组件实例',(完成=>{
这是.compInstance.mapComponent.getNativeInstance()。然后(map=>{
期望(this.fixture.componentInstance).toBeDefined();
期望(this.compInstance.ngonit).toHaveBeenCalled();
期望(this.routeService.getDropdownOptions).toHaveBeenCalled();
expect(this.fixture.componentInstance.messages).not.toBeNull();
expect(this.fixture.componentInstance.messages.length).toEqual(0);
完成();
});
}));
它(`单击停止时应包含正确的支腿',(完成=>{
这是.compInstance.mapComponent.getNativeInstance()。然后(map=>{
此.compInstance.stopLayer.getLayers()[0].fire('click',{latlng: