Reputation: 31
During my unit test i see this error
Error: e does not have a module def (ɵmod property)
I updated to angular v14(
"@angular/cli": "~14.0.0",
) and nx workspace (
"@nrwl/workspace": "14.4.3",
)
The error does not specify which module is causing the problem:
Error: e does not have a module def (ɵmod property)
at transitiveScopesFor(....)
test File:
describe('AppComponent', () => {
let mockOAuthService;
beforeEach(waitForAsync(() => {
// mocks
Object.defineProperty(window, 'matchMedia', {
value: jest.fn(() => {
return { matches: true };
}),
});
mockOAuthService = { logout: jest.fn(), checkAuthentication: () => Promise.resolve(null) };
TestBed.configureTestingModule({
declarations: [AppComponent, AddEntriesButtonComponent],
imports: [
BrowserAnimationsModule,
HttpClientModule,
HsMaterialModule,
RouterTestingModule,
RightsModule,
AuthModule.forRoot(),
NgxsModule.forRoot(),
],
providers: [{ provide: AuthService, useValue: mockOAuthService }, MediaObserver],
teardown: { destroyAfterEach: false },
}).compileComponents();
}));
it('should create the app successfully', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
});
});
I have been stuck with this for days and i cannot find solution anywhere. I have tried deleting node_module and npm ci and other steps in : https://github.com/storybookjs/storybook/issues/13958
It did not help.
I already have this in package json
"scripts": {
"postinstall": "ngcc --properties es2020 browser module main && node ./decorate-angular-cli.js",
}
as stated in ngx-leaflet-draw: Importing module which does not have a ɵmod property
Upvotes: 3
Views: 10599
Reputation: 21
you are looking at the problem in the wrong place. the error is not in the test file. I assume you have created a custom component which you want to reuse in multiple pages. If you are using a shared module do not forget to include "entryComponents:" and if you do not have a shared module then make sure the custom component is in the "entryComponents:[customComponentName]" here is an example:
//shared module
@NgModule({
imports: [
IonicModule.forRoot(),
CommonModule,
MomentModule,
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
declarations: [CustomComponentName],
entryComponents: [CustomComponentName],
exports: [CustomComponentName]
})
export class SharedModule {
static forRoot() {
return {
ngModule: SharedModule,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
}
}
}
Upvotes: 0