-1
votes

TypeError: (options.astTransformers || []). Map n'est pas une fonction angulaire 10

J'ai un test unitaire en cours d'exécution à l'aide du

// jest.lib.config.js
const baseConfig = require('./jest.base.config');

module.exports = {
    ...baseConfig,
    roots: ['<rootDir>/projects'],
};

Lorsque j'exécute la commande npm run test:app cela fonctionnait bien dans Angular 8, j'ai maintenant mis à jour l'angular avec la dernière version 10. J'obtiens une erreur comme ci-dessous sur chaque composant de test

La suite de tests n'a pas pu s'exécuter

module.exports = {
    preset: 'jest-preset-angular',
    setupFilesAfterEnv: ['<rootDir>/setupJest.ts'],
    moduleNameMapper: {
        "^@pts-ngx/core": "<rootDir>/dist/pts-ngx/core",
        "^@pts-ngx/core/(.*)$": "<rootDir>/dist/pts-ngx/core/$1"
    }
};

C'est l'un des composants confrontés à une erreur

const baseConfig = require('./jest.base.config');

module.exports = {
    ...baseConfig,
    roots: ['<rootDir>/src'],
    modulePaths: ['<rootDir>/dist'],
    modulePathIgnorePatterns: ['<rootDir>/src/app/shared'],
    moduleNameMapper: {
        "^@pts-ngx/core": "<rootDir>/dist/pts-ngx/core",
        "^@pts-ngx/core/(.*)$": "<rootDir>/dist/pts-ngx/core/$1",
        'projects/pts-ngx/core/(.*)$': '<rootDir>/projects/pts-ngx/core/$1'
    }
};

Configuration Jest

Configuration Jest.app

describe('DateSelectionComponent', () => {
      let component: DateSelectionComponent;
      let fixture: ComponentFixture<DateSelectionComponent>;
    
      beforeEach(async(() => {
        TestBed.configureTestingModule({
          declarations: [DateSelectionComponent, SafePipe],
          imports: [
            SharedModule,
            NgReduxTestingModule,
            RouterTestingModule.withRoutes([])
          ],
          providers: [
            {
              provide: PageAPIActions, useValue: { setPageState() { } }
            }
          ]
        })
          .compileComponents();
      }));
    
      beforeEach(() => {
        fixture = TestBed.createComponent(DateSelectionComponent);
        component = fixture.componentInstance;
        Object.defineProperties(component, {
          page$: {
            value: of('value'),
            writable: true
          },
          page: {
            value: { destination: 'value' },
            writable: true
          },
          startDate: {
            value: new NgbDate(2019, 2, 27),
            writable: true
          },
          minDate: {
            value: new NgbDate(2019, 2, 27),
            writable: true
          }
        });
        fixture.detectChanges();
      });
    
      it('should create', () => {
        expect(component).toBeTruthy();
      });
    
      it('Should Match Snapshot', async () => {
        (expect(fixture) as any).toMatchSnapshot();
      });
    });

Config de base Jest

TypeError: (options.astTransformers || []).map is not a function

  at ConfigSet.get (node_modules/ts-jest/dist/config/config-set.js:225:64)
  at ConfigSet.tsJest (node_modules/ts-jest/dist/util/memoize.js:43:24)
  at ConfigSet.get (node_modules/ts-jest/dist/config/config-set.js:297:41)
  at ConfigSet.versions (node_modules/ts-jest/dist/util/memoize.js:43:24)
  at ConfigSet.get (node_modules/ts-jest/dist/config/config-set.js:588:32)
  at ConfigSet.jsonValue (node_modules/ts-jest/dist/util/memoize.js:43:24)
  at ConfigSet.get [as cacheKey] (node_modules/ts-jest/dist/config/config-set.js:603:25)
  at TsJestTransformer.getCacheKey (node_modules/ts-jest/dist/ts-jest-transformer.js:126:36)

Config Jest.library

"jest": "^26.4.2",
"jest-preset-angular": "^8.3.1",


0 commentaires

3 Réponses :


0
votes

essayez de mettre à jour "ts-jest" vers la dernière version (26.3.0)


0 commentaires

1
votes

Cela m'aide,

  1. Désinstaller jest-preset-angular
  2. Réinstaller jest-preset-angular
  3. Effacer le cache de plaisanterie
  4. Réessayez

Pour nettoyer le cache sur le fichier angular.json, ajoutez le script ci-dessous

"scripts": {
"clear_jest": "jest --clearCache"
  }

Puis exécutez npm run clear_jest

Si l'option ci-dessus ne fonctionne pas, essayez d'installer explicitement ts-jest par npm install --dev ts-jest

Cette erreur se produit principalement en raison de la mauvaise version de ts-jest dans le fichier package.json.lock.


0 commentaires

0
votes

l'exécution de npm install --dev ts-jest a résolu mon problème.


0 commentaires