You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@echarts.apache.org by GitBox <gi...@apache.org> on 2018/07/13 10:50:39 UTC

[GitHub] diogo5santos5 opened a new issue #8695: Using ECharts with Karma Testing

diogo5santos5 opened a new issue #8695: Using ECharts with Karma Testing
URL: https://github.com/apache/incubator-echarts/issues/8695
 
 
   In my component I have this as the constructor:
   
   `constructor(private es: NgxEchartsService, private sessionService: SessionService, private sorting: SortingService) { }`
   
   And, the first line that I have on my `onInit()` is:
   `    this.es.registerMap('world', worldJson);`
   For the world map chart. It works perfectly, but with this `.spec.ts`:
   
   ````
   import { async, ComponentFixture, TestBed, getTestBed } from '@angular/core/testing';
   
   import { HttpClientTestingModule } from '@angular/common/http/testing';
   import { UsersViewComponent } from './users-view.component';
   import { FormsModule, ReactiveFormsModule } from '../../../node_modules/@angular/forms';
   import { MyDateRangePickerModule } from '../../../node_modules/mydaterangepicker';
   import { NgxEchartsModule, NgxEchartsService } from '../../../node_modules/ngx-echarts';
   import { Observable } from '../../../node_modules/rxjs';
   import { SessionService } from '../Services/session.service';
   import { SortingService } from '../sorting.service';
   
   describe('UsersViewComponent', () => {
     let component: UsersViewComponent;
     let fixture: ComponentFixture<UsersViewComponent>;
   
   
   
     function fireEvent(id,event){
       const nativeElement = fixture.nativeElement;
       const button = nativeElement.querySelector('#'+id);
       button.dispatchEvent(new Event(event));
     }
   
     beforeEach(() => {
       
       // Create a fake TwainService object with a `getQuote()` spy
       const sessionService = jasmine.createSpyObj('sessionService', ['getSessions']);
       // Make the spy return a synchronous Observable with the test data
       var getSessionSpy = sessionService.getSessions.and.returnValue(Observable.of({}));;
   
   
       TestBed.configureTestingModule({
         imports: [FormsModule, ReactiveFormsModule, MyDateRangePickerModule, NgxEchartsModule, HttpClientTestingModule],
         declarations: [UsersViewComponent],
         providers: [
           { provide: NgxEchartsService},
           { provide: SessionService, useValue: sessionService },
           { provide: SortingService }
         ]
       })
         .compileComponents();
   
       fixture = TestBed.createComponent(UsersViewComponent);
       component = fixture.componentInstance;
       fixture.detectChanges();
     });
   
     it('should create', () => {
       fireEvent("worldMapChart","chartInit");
   
       fixture.whenStable().then(() => {
         expect(component).toBeTruthy();
       });
     });
   });
   ```
   
   it gives me: Cannot read property 'registerMap' of undefined, meaning that the Service is not being correctly passed to the component. Any clue?
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@echarts.apache.org
For additional commands, e-mail: dev-help@echarts.apache.org