I'm currently in the process of upgrading my Angular application from version 14 to version 15. Following the steps outlined in the Angular Upgrade guide, I have successfully built the application and can run it using ng serve. However, I am facing persistent errors when running unit tests.
The first error I encountered was a TypeScript issue:
Debug Failure. Unexpected node.
Node HeritageClause was unexpected.
at classElementVisitorWorker (../../node_modules/typescript/lib/typescript.js:93950:37)
at ../../node_modules/typescript/lib/typescript.js:93917:92
at saveStateAndInvoke (../../node_modules/typescript/lib/typescript.js:93773:27)
at ../../node_modules/typescript/lib/typescript.js:93917:45
at visitArrayWorker (../../node_modules/typescript/lib/typescript.js:91402:48)
at Object.visitNodes (../../node_modules/typescript/lib/typescript.js:91366:23)
at visitClassDeclaration (../../node_modules/typescript/lib/typescript.js:94199:117)
at visitTypeScript (../../node_modules/typescript/lib/typescript.js:94067:28)
at visitorWorker (../../node_modules/typescript/lib/typescript.js:93829:24)
at sourceElementVisitorWorker (../../node_modules/typescript/lib/typescript.js:93854:28)
To address this issue, I made changes to update Jest, Webpack, and tslib, which resolved the Node HeritageClause failure. However, another error surfaced in the form of a ReferenceError stating that Window is not defined:
FAIL user-management libs/user-management/src/lib/user-management.module.spec.ts
● Test suite failed to run
ReferenceError: Window is not defined
20 |
21 | constructor(
> 22 | @Inject(WINDOW) private readonly window: Window,
| ^
23 | private readonly componentFactoryResolver: ComponentFactoryResolver,
24 | private readonly applicationRef: ApplicationRef,
25 | private readonly injector
at Object.<anonymous> (../common-ui/src/lib/window/window-manager.service.ts:22:46)
at Object.<anonymous> (../common-ui/src/index.ts:3:1)
at Object.<anonymous> (src/lib/user-management.module.ts:17:1)
at Object.<anonymous> (src/lib/user-management.module.spec.ts:2:1)
Currently, my environment is running on Node version 18.10.0 and Angular version 15.2.10. The Angular application utilizes various libraries and frameworks, including ngrx, nrwl, RxJS, and Jest.
In my package.json file, you will find dependencies related to Angular, Azure, Microsoft, NGRX, and several other packages essential for my project.
Despite these efforts, I am unsure if the issues with Jest are caused by misconfigured packages or if there is a larger underlying problem at play. Any insights or guidance would be highly appreciated.