I have the following:
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
encapsulation: ViewEncapsulation.None,
})
export class AppComponent implements OnInit, OnDestroy {
constructor(
[...]
private internationalization: IntlService,
public translateService: TranslateService,
) {
this.translateService.setDefaultLang('fr');
(this.internationalizationasCldrIntlService).localeId = this.translateService.currentLang;
My question is how do I UNIT-TEST such a component, knowing that actually my test gives me the following
and the test is like this:
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { LayoutModule } from '@progress/kendo-angular-layout';
import { HttpClient } from '@angular/common/http';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { AppComponent } from './app.component';
import { CoreModule } from './core/core.module';
import { KendoModule } from './shared/kendo.module';
import { AppModule } from './app.module';
import '@progress/kendo-angular-intl/locales/fr/all';
describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [
HttpClientTestingModule,
ReactiveFormsModule,
RouterTestingModule,
NoopAnimationsModule,
CoreModule,
LayoutModule,
KendoModule,
AppModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (http: HttpClient) => new TranslateHttpLoader(http, '/assets/i18n/', `.json?v=${new Date().getTime()}`),
deps: [HttpClient]
}
})
],
declarations: [
AppComponent
],
}).compileComponents();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();