3
  • Angular13 project
  • Jest

I get this error endlessly while running a test with Jest:

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From src/app/editors/bcc-context/context-val/components/details/variable/variable-details.component.spec.ts.

          at runMicrotasks (<anonymous>)
          at async Promise.all (index 3)

My jest config looks like this:

const jestConfig = {
  preset: 'jest-preset-angular/presets/defaults-esm',
  extensionsToTreatAsEsm: ['.ts'],
  globals: {
    'ts-jest': {
      useESM: true,
      stringifyContentPathRegex: '\\.(html|svg)$',
      tsconfig: '<rootDir>/tsconfig-esm.spec.json',
    },
  },
  testEnvironment: 'jsdom',
  moduleFileExtensions: ['ts', 'html', 'js', 'json', 'mjs'],
  resolver: 'jest-preset-angular/build/resolvers/ng-jest-resolver.js',
  transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
  transform: {
    '^.+\\.(ts|js|mjs|html|svg)$': 'jest-preset-angular',
  },
  globalSetup: 'jest-preset-angular/global-setup',
  moduleNameMapper: {
    //tslib: 'tslib/tslib.mjs',
    tslib: 'tslib/tslib.es6.js',
    "@shared/(.*)": "<rootDir>/src/app/shared/$1",
    "@editors/(.*)": "<rootDir>/src/app/editors/$1",
    "@dashboard/(.*)": "<rootDir>/src/app/dashboard/$1",
    "@env": "<rootDir>/src/environments/environment",
  },
  setupFilesAfterEnv: ['<rootDir>/src/setup-jest.ts'],
}

export default jestConfig;

jest.useFakeTimers() doesn't change anything

Any other suggestions?

MStephan
  • 131
  • 3

0 Answers0