title: After runMicrotasks "You are trying to `import` a file after the Jest environment has been torn down."
body: <ul>
  <li>Angular13 project</li>
  <li>Jest</li>
  </ul>
  <p>I get this error endlessly while running a test with Jest:</p>
  <pre><code>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 (&lt;anonymous&gt;)
            at async Promise.all (index 3)
  </code></pre>
  <p>My jest config looks like this:</p>
  <pre><code>const jestConfig = {
    preset: 'jest-preset-angular/presets/defaults-esm',
    extensionsToTreatAsEsm: ['.ts'],
    globals: {
      'ts-jest': {
        useESM: true,
        stringifyContentPathRegex: '\\.(html|svg)$',
        tsconfig: '&lt;rootDir&gt;/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',
      &quot;@shared/(.*)&quot;: &quot;&lt;rootDir&gt;/src/app/shared/$1&quot;,
      &quot;@editors/(.*)&quot;: &quot;&lt;rootDir&gt;/src/app/editors/$1&quot;,
      &quot;@dashboard/(.*)&quot;: &quot;&lt;rootDir&gt;/src/app/dashboard/$1&quot;,
      &quot;@env&quot;: &quot;&lt;rootDir&gt;/src/environments/environment&quot;,
    },
    setupFilesAfterEnv: ['&lt;rootDir&gt;/src/setup-jest.ts'],
  }
  
  export default jestConfig;
  </code></pre>
  <p><code>jest.useFakeTimers()</code> doesn't change anything</p>
  <p>Any other suggestions?</p>