1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Cannot read properties of undefined (reading 'module') in Angular unit tests after upgrading...

Discussão em 'Angular' iniciado por Terry Windwalker, Setembro 23, 2024.

  1. Originally, the unit tests are working fine at Angular 15.

    We recently upgrade the project to Angular 17, and now all unit test files (those end with .spec.ts) are throwing errors like this:

    ./src/app/shared/utility/utility.service.spec.ts - Error: Cannot read properties of undefined (reading 'module')


    The test file itself can be as simple as this:

    import { TestBed } from '@angular/core/testing';

    import { UtilityService } from './utility.service';

    describe('UtilityService', () => {
    let service: UtilityService;

    beforeEach(() => {
    TestBed.configureTestingModule({});
    service = TestBed.inject(UtilityService);
    });

    it('should be created', () => {
    expect(service).toBeTruthy();
    });
    });


    I have asked AI and it provided me several suggestions, but the error still persists. The suggestions I have tried include:


    Adding the following to the tsconfig.spec.json inside the compilerOptions section:

    "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "allowJs": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "resolveJsonModule": true


    Ensure the polyfills.ts and test.ts are included in angular.json


    Check if all dependencies are installed correctly.


    Check if any test file has "require" instead of "import".


    Check if the relevant services/components are imported correctly in the test files.


    Create a plain Angular 17 project and compare the difference. (For this one, I tried the configuration in Angular 17 and it works there. Perhaps this is caused by some dependencies.)
    ​

    Now it seems the AI is out of ideas and start repeating itself. So, I am posting a question here to see if anyone has encountered the similar issue before. Thanks in advance for any suggestions or solutions!

    In case it is relevant, this is a Spartacus SAP project and we are using the latest 2211 version.

    Continue reading...

Compartilhe esta Página