Runing test I get this error TypeError: Cannot read properties of undefined (reading 'ngModule')
I dont exactly know what is causing this error, but google said circular dependency issue but I am not sure where to start. Using NX-monorepo with angular and jest for testing Even my tests related to components are failing with the same error, thanks!
module.spec.ts
import { StatusOverviewModule } from './status-overview.module';
describe('StatusOverviewModule', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [StatusOverviewModule],
});
});
it('initializes', () => {
const module = TestBed.inject(StatusOverviewModule);
expect(module).toBeTruthy();
});
});
Status-overview.module
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { RouterModule, Routes } from '@angular/router';
import { TRANSLOCO_SCOPE } from '@ngneat/transloco';
import { SohoComponentsModule } from 'ids-enterprise-ng';
import {
HttpAuthInterceptor,
IonDeskIntegrationModule,
ModuleAccessibilityGuard,
PermissionResource,
} from '@core/ion-desk-integration';
import { scopeLoader, TranslationsModule, TranslationsResolver } from '@core/translations';
import { TilesModule } from '@shared/tiles';
import { StatusOverviewHomeComponent } from './components/status-overview-home/status-overview-home.component';
import { StatusTileCircleComponent } from './components/status-tile-circle/status-tile-circle.component';
import { LOCAL_REST_URL, REST_ENDPOINT } from './constants/status-overview.constants';
import { HttpErrorInterceptor } from './interceptors/http-error.interceptor';
import { LongNumberConversion } from './pipe/long-conversion.pipe';
import { StatusDataService } from './services/status-data.service';
import { StatusOverviewComponent } from './status-overview.component';
export const statusOverviewRoutes: Routes = [
{
path: '',
component: StatusOverviewComponent,
canActivate: [ModuleAccessibilityGuard],
data: {
permissionResource: PermissionResource.ANY,
},
resolve: {
translations: TranslationsResolver,
},
},
];
@NgModule({
imports: [
CommonModule,
SohoComponentsModule,
TranslationsModule,
TilesModule,
RouterModule.forChild(statusOverviewRoutes),
FormsModule,
HttpClientModule,
IonDeskIntegrationModule.forFeature({
devApiPath: LOCAL_REST_URL + '/' + REST_ENDPOINT,
serverApiPath: REST_ENDPOINT,
}),
],
providers: [
{
provide: TRANSLOCO_SCOPE,
useValue: {
scope: 'statusOverview',
loader: scopeLoader((lang, root) => import(`../assets/${root}/${lang}.json`)),
},
},
{ provide: HTTP_INTERCEPTORS,
useClass: HttpErrorInterceptor,
multi: true },
{
provide: HTTP_INTERCEPTORS,
useClass: HttpAuthInterceptor,
multi: true,
},
StatusDataService,
],
declarations: [StatusOverviewComponent, StatusOverviewHomeComponent, StatusTileCircleComponent, LongNumberConversion],
})
export class StatusOverviewModule {}
I guess you missed to wait for the module creation. Try like this: