mdb-completer error by ng test


Topic: mdb-completer error by ng test

duong do asked 7 years ago

Dear supporters, We are using "mdb-completer" component  for our angular 5 project (we have MDB pro license). When we run ng test, we get the following error: "Error: StaticInjectorError(DynamicTestModule)[CompleterService -> LocalData]: StaticInjectorError(Platform: core)[CompleterService -> LocalData]: NullInjectorError: No provider for LocalData!" We have searched in the internet and your website but there is no results. Could you please support us how to solve this problem? Thanks in advance. Regards,Duong Do

Damian Gemza staff answered 7 years ago

Hello, Did you import CompleterData and CompleterService to your component.ts file ?This errors means, that there no provider (service) for your data. Could you show me your app.module.ts file and your component.ts file ? Best Regards, Damian

duong do answered 7 years ago

Hi Damian,

This error is just occur when I run unittest (ng test). I can use "mdb-completer" in my component and it works very well.

After import CompleterData, CompleterService, LocalData, RemoteData, I got another issue:

"Can't resolve all parameters for RemoteData: (?)."

Do you have any idea?

Regards,
Duong

Here is my unittest file (it's hard to read, sorry.):

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { PersonCreateComponent } from './person-create.component';
import { HttpLoaderFactory } from '../../core/i18n/i18n.component';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ConfigService } from '../../core/config/config.service';
import { PersonCreateService } from './person-create.service';
import { IsZipcodeDirective } from '../../shared/validation/input.directive';
import { CompleterService, CompleterData, LocalData, RemoteData } from 'ng-mdb-pro/pro/autocomplete';
import { DatePipe } from '@angular/common';
describe('PersonCreateComponent', () => {
letcomponent:PersonCreateComponent;
letfixture:ComponentFixture<PersonCreateComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
PersonCreateComponent,
IsZipcodeDirective,

],
imports: [
FormsModule,
TranslateModule.forRoot({
loader: {
provide:TranslateLoader,
useFactory:HttpLoaderFactory,
deps: [HttpClient]
}
}),
HttpClientModule,
],
schemas: [NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA],
providers: [
ConfigService,
CompleterService,
LocalData,
RemoteData,
PersonCreateService,
]
})
.compileComponents();
}));
beforeEach(() => {
fixture=TestBed.createComponent(PersonCreateComponent);
component=fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

 


Damian Gemza staff commented 7 years ago

Could you provide me your code? Or even, if it possible, whole project without node modules directory? If you could share project, please send it to d.gemza@mdbootstrap.com I need to know, in which way do you use our MDB Completer component. Best Regards, Damian

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Closed

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No