在我的单元测试中,我看到了这个错误:
Error: e does not have a module def (ɵmod property)
我升级到了 Angular v14(
"@angular/cli": "~14.0.0",
)和nx工作区 (
"@nrwl/workspace": "14.4.3",
错误没有指明哪个模块导致了问题:
Error: e does not have a module def (ɵmod property)
at transitiveScopesFor(....)
测试文件:
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();
});
});
我已经被这个问题困扰了好几天,但是无论在哪里都找不到解决方案。
我尝试了删除 node_module 和运行 npm ci 等其他步骤,参考链接:https://github.com/storybookjs/storybook/issues/13958
但这些方法都没有帮助我解决问题。
我的 package.json 文件中已经有了相关配置。
"scripts": {
"postinstall": "ngcc --properties es2020 browser module main && node ./decorate-angular-cli.js",
}