I have just started with Angular Unit testing, LoginComponent
is dependent on third party module's (Fuse) service FuseConfigService
.
Here is how FuseConfigService
look like
@Injectable({
providedIn: 'root'
})
export class FuseConfigService
{
private _configSubject: BehaviorSubject<any>;
private readonly _defaultConfig: any;
/**
* Constructor
*
* @param {Platform} _platform
* @param {Router} _router
* @param _config
*/
constructor(
private _platform: Platform,
private _router: Router,
@Inject(FUSE_CONFIG) private _config
)
{
And here is how LoginComponent
constructor
look like
constructor(
private fuseConfig: FuseConfigService,
private formBuilder: FormBuilder,
private router: Router,
private authenticationService: AuthService,
private route: ActivatedRoute,
private snackBar: MatSnackBar,
private fuseNavigationService: FuseNavigationService,
private pbiService: PbiService,
private translateService: TranslateService
) {
this.incorrectCredentials = false;
this.loginFormErrors = {
email: {},
password: {},
};
}
I don't know how to configure testing module using TestBed, as it is throwing error like
Error: StaticInjectorError(DynamicTestModule)[FuseConfigService -> InjectionToken fuseCustomConfig]:
StaticInjectorError(Platform: core)[FuseConfigService -> InjectionToken fuseCustomConfig]:
NullInjectorError: No provider for InjectionToken fuseCustomConfig!
This is what I am trying
TestBed.configureTestingModule({
declarations: [LoginComponent],
imports: [FormsModule, ReactiveFormsModule, MatFormFieldModule,
MatInputModule,
MatCheckboxModule,
MatSnackBarModule,
MatButtonModule,
MatRadioModule],
providers: [
FuseConfigService,
{ provide: Router, useClass: class { navigate = jasmine.createSpy("navigate"); } },
FuseNavigationService
]
});
Any help will be appreciated.
See Question&Answers more detail:
os