Closed tobiasschweizer closed 5 years ago
@subotic I do not know how to mock AppInitService
in the specs. The members of AppInitService
are static and so I cannot just inject a mocked instance.
If AppInitService
was an argument in the constructor of an Angular component (an injected service), it could be mocked as follows:
TestBed.configureTestingModule({
imports: [
...
],
declarations: [...],
providers: [
{ provide: AppInitService, useValue: myMockedInstance }
]
I think it could work like this:
@Component({
selector: 'app-leoo-route',
templateUrl: './bebb-route.component.html',
styleUrls: ['./leoo-route.component.scss']
})
export class BebbRouteComponent implements OnInit {
bebbLettertitle: string;
notFound: boolean;
constructor(
private _route: ActivatedRoute,
private _router: Router,
private _beolService: BeolService,
private _searchService: SearchService,
private _appInitService: AppInitService) {
}
ngOnInit() {...}
and then in the spec:
providers: [
{ provide: AppInitService, useValue: { settings: { ontologyIRI: 'test'} } }
]
and then the members would not be static:
@Injectable()
export class AppInitService {
settings: IAppConfig;
coreConfig: KuiCoreConfig;
constructor() {
}
Init() {
return new Promise<void>((resolve, reject) => {
// console.log('AppInitService.init() called');
// do your initialisation stuff here
const data = <IAppConfig> window['tempConfigStorage'];
// console.log('AppInitService: json', data);
this.settings = data;
this.coreConfig = <KuiCoreConfig> {
name: this.settings.appName,
api: this.settings.apiURL,
media: this.settings.iiifURL,
app: this.settings.appURL
};
// console.log('AppInitService: finished');
resolve();
});
}
}
Use
AppInitService
instead ofenvironment
.